Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(location): add continent method #3162

Merged
merged 12 commits into from
Oct 12, 2024
5 changes: 5 additions & 0 deletions src/definitions/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export type LocationDefinition = LocaleEntry<{
*/
country: string[];

/**
* The names of all continents.
*/
continent: string[];
joscha marked this conversation as resolved.
Show resolved Hide resolved

/**
* The [ISO_3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country codes.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/locales/en/location/continent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default [
'Asia',
'Africa',
'North America',
'South America',
'Antarctica',
'Europe',
'Australia',
joscha marked this conversation as resolved.
Show resolved Hide resolved
];
2 changes: 2 additions & 0 deletions src/locales/en/location/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import city_name from './city_name';
import city_pattern from './city_pattern';
import city_prefix from './city_prefix';
import city_suffix from './city_suffix';
import continent from './continent';
import country from './country';
import county from './county';
import direction from './direction';
Expand All @@ -26,6 +27,7 @@ const location: LocationDefinition = {
city_pattern,
city_prefix,
city_suffix,
continent,
country,
county,
direction,
Expand Down
14 changes: 14 additions & 0 deletions src/modules/location/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,20 @@ export class LocationModule extends ModuleBase {
);
}

/**
* Returns a random continent name.
*
* @example
* faker.location.continent() // 'Asia'
*
* @since 9.1.0
*/
continent(): string {
return this.faker.helpers.arrayElement(
this.faker.definitions.location.continent
);
}

/**
* Returns a random [ISO_3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country code.
*
Expand Down
6 changes: 6 additions & 0 deletions test/modules/__snapshots__/location.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ exports[`location > 42 > cardinalDirection > with abbreviated option 1`] = `"E"`

exports[`location > 42 > city 1`] = `"Fort Moses"`;

exports[`location > 42 > continent 1`] = `"North America"`;

exports[`location > 42 > country 1`] = `"Guinea"`;

exports[`location > 42 > countryCode > noArgs 1`] = `"GY"`;
Expand Down Expand Up @@ -144,6 +146,8 @@ exports[`location > 1211 > cardinalDirection > with abbreviated option 1`] = `"W

exports[`location > 1211 > city 1`] = `"The Villages"`;

exports[`location > 1211 > continent 1`] = `"Australia"`;

exports[`location > 1211 > country 1`] = `"Uganda"`;

exports[`location > 1211 > countryCode > noArgs 1`] = `"UM"`;
Expand Down Expand Up @@ -280,6 +284,8 @@ exports[`location > 1337 > cardinalDirection > with abbreviated option 1`] = `"E

exports[`location > 1337 > city 1`] = `"East Duane"`;

exports[`location > 1337 > continent 1`] = `"Africa"`;

exports[`location > 1337 > country 1`] = `"Egypt"`;

exports[`location > 1337 > countryCode > noArgs 1`] = `"EH"`;
Expand Down
2 changes: 2 additions & 0 deletions test/modules/location.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ describe('location', () => {

t.it('country');

t.it('continent');
joscha marked this conversation as resolved.
Show resolved Hide resolved

t.describe('countryCode', (t) => {
t.it('noArgs')
.it('with string alpha-2', 'alpha-2')
Expand Down