Skip to content

Commit 4056ab0

Browse files
authored
feat(location): add continent method (#3162)
1 parent 033c23b commit 4056ab0

6 files changed

Lines changed: 48 additions & 0 deletions

File tree

src/definitions/location.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export type LocationDefinition = LocaleEntry<{
3636
*/
3737
city_suffix: string[];
3838

39+
/**
40+
* The names of all continents.
41+
*/
42+
continent: string[];
43+
3944
/**
4045
* The names of all countries.
4146
*/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default [
2+
'Africa',
3+
'Antarctica',
4+
'Asia',
5+
'Australia',
6+
'Europe',
7+
'North America',
8+
'South America',
9+
];

src/locales/en/location/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import city_name from './city_name';
88
import city_pattern from './city_pattern';
99
import city_prefix from './city_prefix';
1010
import city_suffix from './city_suffix';
11+
import continent from './continent';
1112
import country from './country';
1213
import county from './county';
1314
import direction from './direction';
@@ -26,6 +27,7 @@ const location: LocationDefinition = {
2627
city_pattern,
2728
city_prefix,
2829
city_suffix,
30+
continent,
2931
country,
3032
county,
3133
direction,

src/modules/location/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,20 @@ export class LocationModule extends ModuleBase {
216216
);
217217
}
218218

219+
/**
220+
* Returns a random continent name.
221+
*
222+
* @example
223+
* faker.location.continent() // 'Asia'
224+
*
225+
* @since 9.1.0
226+
*/
227+
continent(): string {
228+
return this.faker.helpers.arrayElement(
229+
this.faker.definitions.location.continent
230+
);
231+
}
232+
219233
/**
220234
* Returns a random [ISO_3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country code.
221235
*

test/modules/__snapshots__/location.spec.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ exports[`location > 42 > cardinalDirection > with abbreviated option 1`] = `"E"`
88

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

11+
exports[`location > 42 > continent 1`] = `"Asia"`;
12+
1113
exports[`location > 42 > country 1`] = `"Guinea"`;
1214

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

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

149+
exports[`location > 1211 > continent 1`] = `"South America"`;
150+
147151
exports[`location > 1211 > country 1`] = `"Uganda"`;
148152

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

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

287+
exports[`location > 1337 > continent 1`] = `"Antarctica"`;
288+
283289
exports[`location > 1337 > country 1`] = `"Egypt"`;
284290

285291
exports[`location > 1337 > countryCode > noArgs 1`] = `"EH"`;

test/modules/location.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ describe('location', () => {
7777

7878
t.it('country');
7979

80+
t.it('continent');
81+
8082
t.describe('countryCode', (t) => {
8183
t.it('noArgs')
8284
.it('with string alpha-2', 'alpha-2')
@@ -145,6 +147,16 @@ describe('location', () => {
145147
describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))(
146148
'random seeded tests for seed %i',
147149
() => {
150+
describe('continent()', () => {
151+
it('returns random continent', () => {
152+
const actual = faker.location.continent();
153+
154+
expect(actual).toBeTruthy();
155+
expect(actual).toBeTypeOf('string');
156+
expect(faker.definitions.location.continent).toContain(actual);
157+
});
158+
});
159+
148160
describe('countryCode()', () => {
149161
it('returns random alpha-2 countryCode', () => {
150162
const countryCode = faker.location.countryCode('alpha-2');

0 commit comments

Comments
 (0)