aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoscha Feth <[email protected]>2024-10-12 14:39:42 +0100
committerGitHub <[email protected]>2024-10-12 15:39:42 +0200
commit4056ab09c64be40d41562284ec64e7531fbaff41 (patch)
treef33217e1fb0d98b52f6076421aaca98757d52aac
parent033c23b109de18dcfaf8abeab4e134a47c57b460 (diff)
downloadfaker-4056ab09c64be40d41562284ec64e7531fbaff41.tar.xz
faker-4056ab09c64be40d41562284ec64e7531fbaff41.zip
feat(location): add `continent` method (#3162)
-rw-r--r--src/definitions/location.ts5
-rw-r--r--src/locales/en/location/continent.ts9
-rw-r--r--src/locales/en/location/index.ts2
-rw-r--r--src/modules/location/index.ts14
-rw-r--r--test/modules/__snapshots__/location.spec.ts.snap6
-rw-r--r--test/modules/location.spec.ts12
6 files changed, 48 insertions, 0 deletions
diff --git a/src/definitions/location.ts b/src/definitions/location.ts
index 5aee4e79..9fbda95f 100644
--- a/src/definitions/location.ts
+++ b/src/definitions/location.ts
@@ -37,6 +37,11 @@ export type LocationDefinition = LocaleEntry<{
city_suffix: string[];
/**
+ * The names of all continents.
+ */
+ continent: string[];
+
+ /**
* The names of all countries.
*/
country: string[];
diff --git a/src/locales/en/location/continent.ts b/src/locales/en/location/continent.ts
new file mode 100644
index 00000000..379b4601
--- /dev/null
+++ b/src/locales/en/location/continent.ts
@@ -0,0 +1,9 @@
+export default [
+ 'Africa',
+ 'Antarctica',
+ 'Asia',
+ 'Australia',
+ 'Europe',
+ 'North America',
+ 'South America',
+];
diff --git a/src/locales/en/location/index.ts b/src/locales/en/location/index.ts
index 7938321d..64ca3268 100644
--- a/src/locales/en/location/index.ts
+++ b/src/locales/en/location/index.ts
@@ -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';
@@ -26,6 +27,7 @@ const location: LocationDefinition = {
city_pattern,
city_prefix,
city_suffix,
+ continent,
country,
county,
direction,
diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts
index 4aabdd8d..4a49e029 100644
--- a/src/modules/location/index.ts
+++ b/src/modules/location/index.ts
@@ -217,6 +217,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.
*
* @param options The code to return or an options object.
diff --git a/test/modules/__snapshots__/location.spec.ts.snap b/test/modules/__snapshots__/location.spec.ts.snap
index b53acbda..a8d24e9a 100644
--- a/test/modules/__snapshots__/location.spec.ts.snap
+++ b/test/modules/__snapshots__/location.spec.ts.snap
@@ -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`] = `"Asia"`;
+
exports[`location > 42 > country 1`] = `"Guinea"`;
exports[`location > 42 > countryCode > noArgs 1`] = `"GY"`;
@@ -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`] = `"South America"`;
+
exports[`location > 1211 > country 1`] = `"Uganda"`;
exports[`location > 1211 > countryCode > noArgs 1`] = `"UM"`;
@@ -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`] = `"Antarctica"`;
+
exports[`location > 1337 > country 1`] = `"Egypt"`;
exports[`location > 1337 > countryCode > noArgs 1`] = `"EH"`;
diff --git a/test/modules/location.spec.ts b/test/modules/location.spec.ts
index 1291efd3..2be7c489 100644
--- a/test/modules/location.spec.ts
+++ b/test/modules/location.spec.ts
@@ -77,6 +77,8 @@ describe('location', () => {
t.it('country');
+ t.it('continent');
+
t.describe('countryCode', (t) => {
t.it('noArgs')
.it('with string alpha-2', 'alpha-2')
@@ -145,6 +147,16 @@ describe('location', () => {
describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))(
'random seeded tests for seed %i',
() => {
+ describe('continent()', () => {
+ it('returns random continent', () => {
+ const actual = faker.location.continent();
+
+ expect(actual).toBeTruthy();
+ expect(actual).toBeTypeOf('string');
+ expect(faker.definitions.location.continent).toContain(actual);
+ });
+ });
+
describe('countryCode()', () => {
it('returns random alpha-2 countryCode', () => {
const countryCode = faker.location.countryCode('alpha-2');