aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinigami <[email protected]>2024-03-18 09:49:27 +0100
committerGitHub <[email protected]>2024-03-18 08:49:27 +0000
commit6dee178558b87b73bba1395c11d2ffe3d156dad1 (patch)
treefa36e0dfe38c0c84fe9aec832293e69c82ec4f89
parente624d0edddfbbb6a67f3a3abfec48ac37e70b976 (diff)
downloadfaker-6dee178558b87b73bba1395c11d2ffe3d156dad1.tar.xz
faker-6dee178558b87b73bba1395c11d2ffe3d156dad1.zip
refactor(location)!: remove v8 deprecated location methods (#2753)
-rw-r--r--docs/guide/upgrading_v9/2753.md16
-rw-r--r--src/modules/location/index.ts842
-rw-r--r--test/all-functional.spec.ts2
-rw-r--r--test/modules/__snapshots__/helpers.spec.ts.snap2
-rw-r--r--test/modules/__snapshots__/location.spec.ts.snap72
-rw-r--r--test/modules/helpers.spec.ts12
-rw-r--r--test/modules/location.spec.ts42
7 files changed, 117 insertions, 871 deletions
diff --git a/docs/guide/upgrading_v9/2753.md b/docs/guide/upgrading_v9/2753.md
new file mode 100644
index 00000000..1886e8b9
--- /dev/null
+++ b/docs/guide/upgrading_v9/2753.md
@@ -0,0 +1,16 @@
+### Remove deprecated location methods
+
+Removed deprecated location methods
+
+| old | replacement |
+| ------------------------------------------------------------------ | ------------------------------------------------------------------ |
+| `faker.location.zipCodeByState` | `faker.location.zipCode({ state })` |
+| `faker.location.cityName` | `faker.location.city` |
+| `faker.location.streetName` | `faker.location.street` |
+| `faker.location.stateAbbr()` | `faker.location.state({ abbreviated: true })` |
+| `faker.location.latitude(max, min, precision)` | `faker.location.latitude({ max, min, precision })` |
+| `faker.location.longitude(max, min, precision)` | `faker.location.longitude({ max, min, precision })` |
+| `faker.location.direction(abbreviated)` | `faker.location.direction({ abbreviated })` |
+| `faker.location.cardinalDirection(abbreviated)` | `faker.location.cardinalDirection({ abbreviated })` |
+| `faker.location.ordinalDirection(abbreviated)` | `faker.location.ordinalDirection({ abbreviated })` |
+| `faker.location.nearbyGPSCoordinate(coordinate, radius, isMetric)` | `faker.location.nearbyGPSCoordinate({ origin, radius, isMetric })` |
diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts
index 92284560..2553e50d 100644
--- a/src/modules/location/index.ts
+++ b/src/modules/location/index.ts
@@ -1,5 +1,4 @@
import { FakerError } from '../../errors/faker-error';
-import { deprecated } from '../../internal/deprecated';
import { ModuleBase } from '../../internal/module-base';
/**
@@ -7,7 +6,7 @@ import { ModuleBase } from '../../internal/module-base';
*
* ### Overview
*
- * For a typical street address for a locale, use [`streetAddress()`](https://fakerjs.dev/api/location.html#streetaddress), [`city()`](https://fakerjs.dev/api/location.html#city), [`state()`](https://fakerjs.dev/api/location.html#state) (or [`stateAbbr()`](https://fakerjs.dev/api/location.html#stateabbr)), and [`zipCode()`](https://fakerjs.dev/api/location.html#zipcode). Most locales provide localized versions for a specific country.
+ * For a typical street address for a locale, use [`streetAddress()`](https://fakerjs.dev/api/location.html#streetaddress), [`city()`](https://fakerjs.dev/api/location.html#city), [`state()`](https://fakerjs.dev/api/location.html#state)), and [`zipCode()`](https://fakerjs.dev/api/location.html#zipcode). Most locales provide localized versions for a specific country.
*
* If you need latitude and longitude coordinates, use [`latitude()`](https://fakerjs.dev/api/location.html#latitude) and [`longitude()`](https://fakerjs.dev/api/location.html#longitude), or [`nearbyGPSCoordinate()`](https://fakerjs.dev/api/location.html#nearbygpscoordinate) for a latitude/longitude near a given location.
*
@@ -81,53 +80,6 @@ export class LocationModule extends ModuleBase {
}
/**
- * Generates random zip code from state abbreviation.
- *
- * If the current locale does not have a corresponding `postcode_by_state` definition, an error is thrown.
- *
- * @param options A state abbreviation or an options object.
- * @param options.state The abbreviation of the state to generate the zip code for.
- * If not specified, a random zip code is generated according to the locale's zip format.
- *
- * @see faker.location.zipCode(): For the replacement method.
- *
- * @example
- * fakerEN_US.location.zipCodeByState("AK") // '99595'
- * fakerEN_US.location.zipCodeByState() // '47683-9880'
- * fakerEN_US.location.zipCodeByState({ state: "AK" }) // '99595'
- *
- * @since 8.0.0
- *
- * @deprecated Use `faker.location.zipCode({ state })` instead.
- */
- zipCodeByState(
- options:
- | string
- | {
- /**
- * The abbreviation of the state to generate the zip code for.
- * If not specified, a random zip code is generated according to the locale's zip format.
- */
- state?: string;
- } = {}
- ): string {
- deprecated({
- deprecated: 'faker.location.zipCodeByState',
- proposed: 'faker.location.zipCode({ state })',
- since: '8.0',
- until: '9.0',
- });
-
- if (typeof options === 'string') {
- options = { state: options };
- }
-
- const { state } = options;
-
- return this.zipCode({ state });
- }
-
- /**
* Generates a random localized city name.
*
* @example
@@ -143,31 +95,6 @@ export class LocationModule extends ModuleBase {
}
/**
- * Returns a random city name from a list of real cities for the locale.
- *
- * @see faker.location.city(): For the replacement method.
- *
- * @example
- * faker.location.cityName() // 'San Rafael'
- * fakerDE.location.cityName() // 'Nürnberg'
- *
- * @since 8.0.0
- *
- * @deprecated Use `faker.location.city()` instead.
- */
- cityName(): string {
- deprecated({
- deprecated: 'faker.location.cityName',
- proposed: 'faker.location.city',
- since: '8.0',
- until: '9.0',
- });
- return this.faker.helpers.arrayElement(
- this.faker.definitions.location.city_name
- );
- }
-
- /**
* Generates a random building number.
*
* @example
@@ -201,30 +128,6 @@ export class LocationModule extends ModuleBase {
}
/**
- * Returns a random localized street name.
- *
- * @see faker.location.street(): For the replacement method.
- *
- * @example
- * fakerDE.location.streetName() // 'Cavill Avenue'
- *
- * @since 8.0.0
- *
- * @deprecated Use `faker.location.street()` instead.
- */
- streetName(): string {
- deprecated({
- deprecated: 'faker.location.streetName',
- proposed: 'faker.location.street',
- since: '8.0',
- until: '9.0',
- });
- return this.faker.helpers.arrayElement(
- this.faker.definitions.location.street_name
- );
- }
-
- /**
* Generates a random localized street address.
*
* @param options Whether to use a full address or an options object.
@@ -412,26 +315,6 @@ export class LocationModule extends ModuleBase {
}
/**
- * Returns a random localized state's abbreviated name from this country.
- *
- * @example
- * faker.location.stateAbbr() // 'ND'
- *
- * @since 8.0.0
- *
- * @deprecated Use `faker.location.state({ abbreviated: true })` instead.
- */
- stateAbbr(): string {
- deprecated({
- deprecated: 'faker.location.stateAbbr()',
- proposed: 'faker.location.state({ abbreviated: true })',
- since: '8.0',
- until: '9.0',
- });
- return this.state({ abbreviated: true });
- }
-
- /**
* Generates a random latitude.
*
* @param options An options object.
@@ -447,143 +330,29 @@ export class LocationModule extends ModuleBase {
*
* @since 8.0.0
*/
- latitude(options?: {
- /**
- * The upper bound for the latitude to generate.
- *
- * @default 90
- */
- max?: number;
- /**
- * The lower bound for the latitude to generate.
- *
- * @default -90
- */
- min?: number;
- /**
- * The number of decimal points of precision for the latitude.
- *
- * @default 4
- */
- precision?: number;
- }): number;
- /**
- * Generates a random latitude.
- *
- * @param max The upper bound for the latitude to generate. Defaults to `90`.
- * @param min The lower bound for the latitude to generate. Defaults to `-90`.
- * @param precision The number of decimal points of precision for the latitude. Defaults to `4`.
- *
- * @example
- * faker.location.latitude() // -30.9501
- * faker.location.latitude(10) // 5.7225
- * faker.location.latitude(10, -10) // -9.6273
- * faker.location.latitude(10, -10, 5) // 2.68452
- *
- * @since 8.0.0
- *
- * @deprecated Use `faker.location.latitude({ max, min, precision })` instead.
- */
- latitude(max?: number, min?: number, precision?: number): number;
- /**
- * Generates a random latitude.
- *
- * @param options The upper bound for the latitude or an options object.
- * @param options.max The upper bound for the latitude to generate. Defaults to `90`.
- * @param options.min The lower bound for the latitude to generate. Defaults to `-90`.
- * @param options.precision The number of decimal points of precision for the latitude. Defaults to `4`.
- * @param legacyMin The lower bound for the latitude to generate. Defaults to `-90`.
- * @param legacyPrecision The number of decimal points of precision for the latitude. Defaults to `4`.
- *
- * @example
- * faker.location.latitude() // -30.9501
- * faker.location.latitude({ max: 10 }) // 5.7225
- * faker.location.latitude({ max: 10, min: -10 }) // -9.6273
- * faker.location.latitude({ max: 10, min: -10, precision: 5 }) // 2.68452
- *
- * @since 8.0.0
- */
- latitude(
- options:
- | number
- | {
- /**
- * The upper bound for the latitude to generate.
- *
- * @default 90
- */
- max?: number;
- /**
- * The lower bound for the latitude to generate.
- *
- * @default -90
- */
- min?: number;
- /**
- * The number of decimal points of precision for the latitude.
- *
- * @default 4
- */
- precision?: number;
- },
- legacyMin?: number,
- legacyPrecision?: number
- ): number;
- /**
- * Generates a random latitude.
- *
- * @param options The upper bound for the latitude or an options object.
- * @param options.max The upper bound for the latitude to generate. Defaults to `90`.
- * @param options.min The lower bound for the latitude to generate. Defaults to `-90`.
- * @param options.precision The number of decimal points of precision for the latitude. Defaults to `4`.
- * @param legacyMin The lower bound for the latitude to generate. Defaults to `-90`.
- * @param legacyPrecision The number of decimal points of precision for the latitude. Defaults to `4`.
- *
- * @example
- * faker.location.latitude() // -30.9501
- * faker.location.latitude({ max: 10 }) // 5.7225
- * faker.location.latitude({ max: 10, min: -10 }) // -9.6273
- * faker.location.latitude({ max: 10, min: -10, precision: 5 }) // 2.68452
- *
- * @since 8.0.0
- */
latitude(
- options:
- | number
- | {
- /**
- * The upper bound for the latitude to generate.
- *
- * @default 90
- */
- max?: number;
- /**
- * The lower bound for the latitude to generate.
- *
- * @default -90
- */
- min?: number;
- /**
- * The number of decimal points of precision for the latitude.
- *
- * @default 4
- */
- precision?: number;
- } = {},
- legacyMin = -90,
- legacyPrecision = 4
+ options: {
+ /**
+ * The upper bound for the latitude to generate.
+ *
+ * @default 90
+ */
+ max?: number;
+ /**
+ * The lower bound for the latitude to generate.
+ *
+ * @default -90
+ */
+ min?: number;
+ /**
+ * The number of decimal points of precision for the latitude.
+ *
+ * @default 4
+ */
+ precision?: number;
+ } = {}
): number {
- if (typeof options === 'number') {
- deprecated({
- deprecated: 'faker.location.latitude(max, min, precision)',
- proposed: 'faker.location.latitude({ max, min, precision })',
- since: '8.0',
- until: '9.0',
- });
- options = { max: options };
- }
-
- const { max = 90, min = legacyMin, precision = legacyPrecision } = options;
+ const { max = 90, min = -90, precision = 4 } = options;
return this.faker.number.float({ min, max, fractionDigits: precision });
}
@@ -604,143 +373,29 @@ export class LocationModule extends ModuleBase {
*
* @since 8.0.0
*/
- longitude(options?: {
- /**
- * The upper bound for the longitude to generate.
- *
- * @default 180
- */
- max?: number;
- /**
- * The lower bound for the longitude to generate.
- *
- * @default -180
- */
- min?: number;
- /**
- * The number of decimal points of precision for the longitude.
- *
- * @default 4
- */
- precision?: number;
- }): number;
- /**
- * Generates a random longitude.
- *
- * @param max The upper bound for the longitude to generate. Defaults to `180`.
- * @param min The lower bound for the longitude to generate. Defaults to `-180`.
- * @param precision The number of decimal points of precision for the longitude. Defaults to `4`.
- *
- * @example
- * faker.location.longitude() // -30.9501
- * faker.location.longitude(10) // 5.7225
- * faker.location.longitude(10, -10) // -9.6273
- * faker.location.longitude(10, -10, 5) // 2.68452
- *
- * @since 8.0.0
- *
- * @deprecated Use `faker.location.longitude({ max, min, precision })` instead.
- */
- longitude(max?: number, min?: number, precision?: number): number;
- /**
- * Generates a random longitude.
- *
- * @param options The upper bound for the longitude or an options object.
- * @param options.max The upper bound for the longitude to generate. Defaults to `180`.
- * @param options.min The lower bound for the longitude to generate. Defaults to `-180`.
- * @param options.precision The number of decimal points of precision for the longitude. Defaults to `4`.
- * @param legacyMin The lower bound for the longitude to generate. Defaults to `-180`.
- * @param legacyPrecision The number of decimal points of precision for the longitude. Defaults to `4`.
- *
- * @example
- * faker.location.longitude() // -30.9501
- * faker.location.longitude({ max: 10 }) // 5.7225
- * faker.location.longitude({ max: 10, min: -10 }) // -9.6273
- * faker.location.longitude({ max: 10, min: -10, precision: 5 }) // 2.68452
- *
- * @since 8.0.0
- */
- longitude(
- options?:
- | number
- | {
- /**
- * The upper bound for the longitude to generate.
- *
- * @default 180
- */
- max?: number;
- /**
- * The lower bound for the longitude to generate.
- *
- * @default -180
- */
- min?: number;
- /**
- * The number of decimal points of precision for the longitude.
- *
- * @default 4
- */
- precision?: number;
- },
- legacyMin?: number,
- legacyPrecision?: number
- ): number;
- /**
- * Generates a random longitude.
- *
- * @param options An options object.
- * @param options.max The upper bound for the longitude to generate. Defaults to `180`.
- * @param options.min The lower bound for the longitude to generate. Defaults to `-180`.
- * @param options.precision The number of decimal points of precision for the longitude. Defaults to `4`.
- * @param legacyMin The lower bound for the longitude to generate. Defaults to `-180`.
- * @param legacyPrecision The number of decimal points of precision for the longitude. Defaults to `4`.
- *
- * @example
- * faker.location.longitude() // -154.0226
- * faker.location.longitude({ max: 10 }) // 2.4387
- * faker.location.longitude({ max: 10, min: -10 }) // 6.9126
- * faker.location.longitude({ max: 10, min: -10, precision: 5 }) // -4.03620
- *
- * @since 8.0.0
- */
longitude(
- options:
- | number
- | {
- /**
- * The upper bound for the longitude to generate.
- *
- * @default 180
- */
- max?: number;
- /**
- * The lower bound for the longitude to generate.
- *
- * @default -180
- */
- min?: number;
- /**
- * The number of decimal points of precision for the longitude.
- *
- * @default 4
- */
- precision?: number;
- } = {},
- legacyMin = -180,
- legacyPrecision = 4
+ options: {
+ /**
+ * The upper bound for the longitude to generate.
+ *
+ * @default 180
+ */
+ max?: number;
+ /**
+ * The lower bound for the longitude to generate.
+ *
+ * @default -180
+ */
+ min?: number;
+ /**
+ * The number of decimal points of precision for the longitude.
+ *
+ * @default 4
+ */
+ precision?: number;
+ } = {}
): number {
- if (typeof options === 'number') {
- deprecated({
- deprecated: 'faker.location.longitude(max, min, precision)',
- proposed: 'faker.location.longitude({ max, min, precision })',
- since: '8.0',
- until: '9.0',
- });
- options = { max: options };
- }
-
- const { max = 180, min = legacyMin, precision = legacyPrecision } = options;
+ const { max = 180, min = -180, precision = 4 } = options;
return this.faker.number.float({ max, min, fractionDigits: precision });
}
@@ -758,93 +413,17 @@ export class LocationModule extends ModuleBase {
*
* @since 8.0.0
*/
- direction(options?: {
- /**
- * If true this will return abbreviated directions (NW, E, etc).
- * Otherwise this will return the long name.
- *
- * @default false
- */
- abbreviated?: boolean;
- }): string;
- /**
- * Returns a random direction (cardinal and ordinal; northwest, east, etc).
- *
- * @param abbreviated If true this will return abbreviated directions (NW, E, etc).
- * Otherwise this will return the long name. Defaults to `false`.
- *
- * @example
- * faker.location.direction() // 'Northeast'
- * faker.location.direction(false) // 'South'
- * faker.location.direction(true) // 'NE'
- *
- * @since 8.0.0
- *
- * @deprecated Use `faker.location.direction({ abbreviated })` instead.
- */
- direction(abbreviated?: boolean): string;
- /**
- * Returns a random direction (cardinal and ordinal; northwest, east, etc).
- *
- * @param options Whether to use abbreviated or an options object.
- * @param options.abbreviated If true this will return abbreviated directions (NW, E, etc).
- * Otherwise this will return the long name. Defaults to `false`.
- *
- * @example
- * faker.location.direction() // 'Northeast'
- * faker.location.direction({ abbreviated: true }) // 'SW'
- *
- * @since 8.0.0
- */
- direction(
- options?:
- | boolean
- | {
- /**
- * If true this will return abbreviated directions (NW, E, etc).
- * Otherwise this will return the long name.
- *
- * @default false
- */
- abbreviated?: boolean;
- }
- ): string;
- /**
- * Returns a random direction (cardinal and ordinal; northwest, east, etc).
- *
- * @param options Whether to use abbreviated or an options object.
- * @param options.abbreviated If true this will return abbreviated directions (NW, E, etc).
- * Otherwise this will return the long name. Defaults to `false`.
- *
- * @example
- * faker.location.direction() // 'Northeast'
- * faker.location.direction({ abbreviated: true }) // 'SW'
- *
- * @since 8.0.0
- */
direction(
- options:
- | boolean
- | {
- /**
- * If true this will return abbreviated directions (NW, E, etc).
- * Otherwise this will return the long name.
- *
- * @default false
- */
- abbreviated?: boolean;
- } = {}
+ options: {
+ /**
+ * If true this will return abbreviated directions (NW, E, etc).
+ * Otherwise this will return the long name.
+ *
+ * @default false
+ */
+ abbreviated?: boolean;
+ } = {}
): string {
- if (typeof options === 'boolean') {
- deprecated({
- deprecated: 'faker.location.direction(abbreviated)',
- proposed: 'faker.location.direction({ abbreviated })',
- since: '8.0',
- until: '9.0',
- });
- options = { abbreviated: options };
- }
-
const { abbreviated = false } = options;
if (!abbreviated) {
@@ -871,94 +450,19 @@ export class LocationModule extends ModuleBase {
*
* @since 8.0.0
*/
- cardinalDirection(options?: {
- /**
- * If true this will return abbreviated directions (N, E, etc).
- * Otherwise this will return the long name.
- *
- * @default false
- */
- abbreviated?: boolean;
- }): string;
- /**
- * Returns a random cardinal direction (north, east, south, west).
- *
- * @param abbreviated If true this will return abbreviated directions (N, E, etc).
- * Otherwise this will return the long name. Defaults to `false`.
- *
- * @example
- * faker.location.cardinalDirection() // 'North'
- * faker.location.cardinalDirection(false) // 'South'
- * faker.location.cardinalDirection(true) // 'N'
- *
- * @since 8.0.0
- *
- * @deprecated Use `faker.location.cardinalDirection({ abbreviated })` instead.
- */
- cardinalDirection(abbreviated?: boolean): string;
- /**
- * Returns a random cardinal direction (north, east, south, west).
- *
- * @param options Whether to use abbreviated or an options object. Defaults to`{}`.
- * @param options.abbreviated If true this will return abbreviated directions (N, E, etc).
- * Otherwise this will return the long name. Defaults to `false`.
- *
- * @example
- * faker.location.cardinalDirection() // 'North'
- * faker.location.cardinalDirection({ abbreviated: true }) // 'W'
- *
- * @since 8.0.0
- */
cardinalDirection(
- options?:
- | boolean
- | {
- /**
- * If true this will return abbreviated directions (N, E, etc).
- * Otherwise this will return the long name.
- *
- * @default false
- */
- abbreviated?: boolean;
- }
- ): string;
- /**
- * Returns a random cardinal direction (north, east, south, west).
- *
- * @param options Whether to use abbreviated or an options object.
- * @param options.abbreviated If true this will return abbreviated directions (N, E, etc).
- * Otherwise this will return the long name. Defaults to `false`.
- *
- * @example
- * faker.location.cardinalDirection() // 'North'
- * faker.location.cardinalDirection({ abbreviated: true }) // 'W'
- *
- * @since 8.0.0
- */
- cardinalDirection(
- options:
- | boolean
- | {
- /**
- * If true this will return abbreviated directions (N, E, etc).
- * Otherwise this will return the long name.
- *
- * @default false
- */
- abbreviated?: boolean;
- } = {}
+ options: {
+ /**
+ * If true this will return abbreviated directions (N, E, etc).
+ * Otherwise this will return the long name.
+ *
+ * @default false
+ */
+ abbreviated?: boolean;
+ } = {}
): string {
- if (typeof options === 'boolean') {
- deprecated({
- deprecated: 'faker.location.cardinalDirection(abbreviated)',
- proposed: 'faker.location.cardinalDirection({ abbreviated })',
- since: '8.0',
- until: '9.0',
- });
- options = { abbreviated: options };
- }
-
const { abbreviated = false } = options;
+
if (!abbreviated) {
return this.faker.helpers.arrayElement(
this.faker.definitions.location.direction.slice(0, 4)
@@ -983,94 +487,19 @@ export class LocationModule extends ModuleBase {
*
* @since 8.0.0
*/
- ordinalDirection(options?: {
- /**
- * If true this will return abbreviated directions (NW, SE, etc).
- * Otherwise this will return the long name.
- *
- * @default false
- */
- abbreviated?: boolean;
- }): string;
- /**
- * Returns a random ordinal direction (northwest, southeast, etc).
- *
- * @param abbreviated If true this will return abbreviated directions (NW, SE, etc).
- * Otherwise this will return the long name. Defaults to `false`.
- *
- * @example
- * faker.location.ordinalDirection() // 'Northeast'
- * faker.location.ordinalDirection(false) // 'Northwest'
- * faker.location.ordinalDirection(true) // 'NE'
- *
- * @since 8.0.0
- *
- * @deprecated Use `faker.location.ordinalDirection({ abbreviated })` instead.
- */
- ordinalDirection(abbreviated?: boolean): string;
- /**
- * Returns a random ordinal direction (northwest, southeast, etc).
- *
- * @param options Whether to use abbreviated or an options object.
- * @param options.abbreviated If true this will return abbreviated directions (NW, SE, etc).
- * Otherwise this will return the long name. Defaults to `false`.
- *
- * @example
- * faker.location.ordinalDirection() // 'Northeast'
- * faker.location.ordinalDirection({ abbreviated: true }) // 'SW'
- *
- * @since 8.0.0
- */
ordinalDirection(
- options?:
- | boolean
- | {
- /**
- * If true this will return abbreviated directions (NW, SE, etc).
- * Otherwise this will return the long name.
- *
- * @default false
- */
- abbreviated?: boolean;
- }
- ): string;
- /**
- * Returns a random ordinal direction (northwest, southeast, etc).
- *
- * @param options Whether to use abbreviated or an options object.
- * @param options.abbreviated If true this will return abbreviated directions (NW, SE, etc).
- * Otherwise this will return the long name. Defaults to `false`.
- *
- * @example
- * faker.location.ordinalDirection() // 'Northeast'
- * faker.location.ordinalDirection({ abbreviated: true }) // 'SW'
- *
- * @since 8.0.0
- */
- ordinalDirection(
- options:
- | boolean
- | {
- /**
- * If true this will return abbreviated directions (NW, SE, etc).
- * Otherwise this will return the long name.
- *
- * @default false
- */
- abbreviated?: boolean;
- } = {}
+ options: {
+ /**
+ * If true this will return abbreviated directions (NW, SE, etc).
+ * Otherwise this will return the long name.
+ *
+ * @default false
+ */
+ abbreviated?: boolean;
+ } = {}
): string {
- if (typeof options === 'boolean') {
- deprecated({
- deprecated: 'faker.location.ordinalDirection(abbreviated)',
- proposed: 'faker.location.ordinalDirection({ abbreviated })',
- since: '8.0',
- until: '9.0',
- });
- options = { abbreviated: options };
- }
-
const { abbreviated = false } = options;
+
if (!abbreviated) {
return this.faker.helpers.arrayElement(
this.faker.definitions.location.direction.slice(4, 8)
@@ -1098,116 +527,27 @@ export class LocationModule extends ModuleBase {
*
* @since 8.0.0
*/
- nearbyGPSCoordinate(options?: {
- /**
- * The original coordinate to get a new coordinate close to.
- */
- origin?: [latitude: number, longitude: number];
- /**
- * The maximum distance from the given coordinate to the new coordinate.
- *
- * @default 10
- */
- radius?: number;
- /**
- * If `true` assume the radius to be in kilometers. If `false` for miles.
- *
- * @default false
- */
- isMetric?: boolean;
- }): [latitude: number, longitude: number];
- /**
- * Generates a random GPS coordinate within the specified radius from the given coordinate.
- *
- * @param coordinate The original coordinate to get a new coordinate close to.
- * If no coordinate is given, a random one will be chosen.
- * @param radius The maximum distance from the given coordinate to the new coordinate. Defaults to `10`.
- * @param isMetric If `true` assume the radius to be in kilometers. If `false` for miles. Defaults to `false`.
- *
- * @example
- * faker.location.nearbyGPSCoordinate() // [ 33.8475, -170.5953 ]
- * faker.location.nearbyGPSCoordinate([33, -170]) // [ 33.0165, -170.0636 ]
- * faker.location.nearbyGPSCoordinate([33, -170], 1000, true) // [ 37.9163, -179.2408 ]
- *
- * @since 8.0.0
- *
- * @deprecated Use `faker.location.nearbyGPSCoordinate({ origin, radius, isMetric })` instead.
- */
nearbyGPSCoordinate(
- coordinate?: [latitude: number, longitude: number],
- radius?: number,
- isMetric?: boolean
- ): [latitude: number, longitude: number];
- /**
- * Generates a random GPS coordinate within the specified radius from the given coordinate.
- *
- * @param options The options for generating a GPS coordinate.
- * @param options.origin The original coordinate to get a new coordinate close to.
- * If no coordinate is given, a random one will be chosen.
- * @param options.radius The maximum distance from the given coordinate to the new coordinate. Defaults to `10`.
- * @param options.isMetric If `true` assume the radius to be in kilometers. If `false` for miles. Defaults to `false`.
- * @param legacyRadius Deprecated, use `options.radius` instead. Defaults to `10`.
- * @param legacyIsMetric Deprecated, use `options.isMetric` instead. Defaults to `false`.
- *
- * @example
- * faker.location.nearbyGPSCoordinate() // [ 33.8475, -170.5953 ]
- * faker.location.nearbyGPSCoordinate({ origin: [33, -170] }) // [ 33.0165, -170.0636 ]
- * faker.location.nearbyGPSCoordinate({ origin: [33, -170], radius: 1000, isMetric: true }) // [ 37.9163, -179.2408 ]
- *
- * @since 8.0.0
- */
- nearbyGPSCoordinate(
- options?:
- | [latitude: number, longitude: number]
- | {
- /**
- * The original coordinate to get a new coordinate close to.
- */
- origin?: [latitude: number, longitude: number];
- /**
- * The maximum distance from the given coordinate to the new coordinate.
- *
- * @default 10
- */
- radius?: number;
- /**
- * If `true` assume the radius to be in kilometers. If `false` for miles.
- *
- * @default false
- */
- isMetric?: boolean;
- },
- legacyRadius?: number,
- legacyIsMetric?: boolean
- ): [latitude: number, longitude: number];
- nearbyGPSCoordinate(
- options:
- | [latitude: number, longitude: number]
- | {
- origin?: [latitude: number, longitude: number];
- radius?: number;
- isMetric?: boolean;
- } = {},
- legacyRadius: number = 10,
- legacyIsMetric: boolean = false
+ options: {
+ /**
+ * The original coordinate to get a new coordinate close to.
+ */
+ origin?: [latitude: number, longitude: number];
+ /**
+ * The maximum distance from the given coordinate to the new coordinate.
+ *
+ * @default 10
+ */
+ radius?: number;
+ /**
+ * If `true` assume the radius to be in kilometers. If `false` for miles.
+ *
+ * @default false
+ */
+ isMetric?: boolean;
+ } = {}
): [latitude: number, longitude: number] {
- if (Array.isArray(options)) {
- deprecated({
- deprecated:
- 'faker.location.nearbyGPSCoordinate(coordinate, radius, isMetric)',
- proposed:
- 'faker.location.nearbyGPSCoordinate({ origin, radius, isMetric })',
- since: '8.0',
- until: '9.0',
- });
- options = { origin: options };
- }
-
- const {
- origin,
- radius = legacyRadius,
- isMetric = legacyIsMetric,
- } = options;
+ const { origin, radius = 10, isMetric = false } = options;
// If there is no origin, the best we can do is return a random GPS coordinate.
if (origin == null) {
diff --git a/test/all-functional.spec.ts b/test/all-functional.spec.ts
index 577e6498..12b69ba1 100644
--- a/test/all-functional.spec.ts
+++ b/test/all-functional.spec.ts
@@ -51,9 +51,7 @@ const BROKEN_LOCALE_METHODS = {
},
location: {
state: ['az', 'nb_NO', 'ro_MD', 'sk'],
- stateAbbr: ['cs_CZ', 'ro_MD', 'sk'],
zipCode: ['en_HK'],
- zipCodeByState: ['en_HK'],
},
string: {
fromCharacters: '*',
diff --git a/test/modules/__snapshots__/helpers.spec.ts.snap b/test/modules/__snapshots__/helpers.spec.ts.snap
index d8a78602..92801e06 100644
--- a/test/modules/__snapshots__/helpers.spec.ts.snap
+++ b/test/modules/__snapshots__/helpers.spec.ts.snap
@@ -263,7 +263,7 @@ exports[`helpers > 1211 > fake > with a static template 1`] = `"my test string"`
exports[`helpers > 1211 > fake > with empty string 1`] = `""`;
-exports[`helpers > 1211 > fake > with multiple dynamic templates 1`] = `"The Villages"`;
+exports[`helpers > 1211 > fake > with multiple dynamic templates 1`] = `"396 St George's Road"`;
exports[`helpers > 1211 > fake > with multiple static templates 1`] = `"C"`;
diff --git a/test/modules/__snapshots__/location.spec.ts.snap b/test/modules/__snapshots__/location.spec.ts.snap
index a29416ed..5d4b1d31 100644
--- a/test/modules/__snapshots__/location.spec.ts.snap
+++ b/test/modules/__snapshots__/location.spec.ts.snap
@@ -6,12 +6,8 @@ exports[`location > 42 > cardinalDirection > noArgs 1`] = `"East"`;
exports[`location > 42 > cardinalDirection > with abbreviated option 1`] = `"E"`;
-exports[`location > 42 > cardinalDirection > with boolean 1`] = `"East"`;
-
exports[`location > 42 > city 1`] = `"Fort Moses"`;
-exports[`location > 42 > cityName 1`] = `"Hamilton"`;
-
exports[`location > 42 > country 1`] = `"Guinea"`;
exports[`location > 42 > countryCode > noArgs 1`] = `"GY"`;
@@ -34,42 +30,28 @@ exports[`location > 42 > direction > noArgs 1`] = `"South"`;
exports[`location > 42 > direction > with abbreviated option 1`] = `"S"`;
-exports[`location > 42 > direction > with boolean 1`] = `"South"`;
-
exports[`location > 42 > latitude > noArgs 1`] = `-22.5828`;
-exports[`location > 42 > latitude > with max 1`] = `-52.546`;
-
exports[`location > 42 > latitude > with max and min option 1`] = `-2.5092`;
exports[`location > 42 > latitude > with max option 1`] = `-52.546`;
exports[`location > 42 > latitude > with max, min and precision option 1`] = `-2.5091976231`;
-exports[`location > 42 > latitude > with min 1`] = `27.454`;
-
exports[`location > 42 > latitude > with min option 1`] = `27.454`;
-exports[`location > 42 > latitude > with precision 1`] = `-22.5827786075`;
-
exports[`location > 42 > latitude > with precision option 1`] = `-22.5827786075`;
exports[`location > 42 > longitude > noArgs 1`] = `-45.1656`;
-exports[`location > 42 > longitude > with max 1`] = `-108.8374`;
-
exports[`location > 42 > longitude > with max and min option 1`] = `-2.5092`;
exports[`location > 42 > longitude > with max option 1`] = `-108.8374`;
exports[`location > 42 > longitude > with max, min and precision option 1`] = `-2.5091976231`;
-exports[`location > 42 > longitude > with min 1`] = `61.1626`;
-
exports[`location > 42 > longitude > with min option 1`] = `61.1626`;
-exports[`location > 42 > longitude > with precision 1`] = `-45.165557215`;
-
exports[`location > 42 > longitude > with precision option 1`] = `-45.165557215`;
exports[`location > 42 > nearbyGPSCoordinate > near origin 1`] = `
@@ -132,16 +114,12 @@ exports[`location > 42 > ordinalDirection > noArgs 1`] = `"Northwest"`;
exports[`location > 42 > ordinalDirection > with abbreviated option 1`] = `"NW"`;
-exports[`location > 42 > ordinalDirection > with boolean 1`] = `"Northwest"`;
-
exports[`location > 42 > secondaryAddress 1`] = `"Apt. 975"`;
exports[`location > 42 > state > noArgs 1`] = `"Maine"`;
exports[`location > 42 > state > with options 1`] = `"ME"`;
-exports[`location > 42 > stateAbbr 1`] = `"ME"`;
-
exports[`location > 42 > street 1`] = `"Wiegand Ridges"`;
exports[`location > 42 > streetAddress > noArgs 1`] = `"9751 Anderson Throughway"`;
@@ -158,20 +136,14 @@ exports[`location > 42 > zipCode > with format option 1`] = `"397-511"`;
exports[`location > 42 > zipCode > with string 1`] = `"397"`;
-exports[`location > 42 > zipCodeByState > noArgs 1`] = `"97511"`;
-
exports[`location > 1211 > buildingNumber 1`] = `"929"`;
exports[`location > 1211 > cardinalDirection > noArgs 1`] = `"West"`;
exports[`location > 1211 > cardinalDirection > with abbreviated option 1`] = `"W"`;
-exports[`location > 1211 > cardinalDirection > with boolean 1`] = `"West"`;
-
exports[`location > 1211 > city 1`] = `"The Villages"`;
-exports[`location > 1211 > cityName 1`] = `"Utica"`;
-
exports[`location > 1211 > country 1`] = `"Uganda"`;
exports[`location > 1211 > countryCode > noArgs 1`] = `"UM"`;
@@ -194,42 +166,28 @@ exports[`location > 1211 > direction > noArgs 1`] = `"Southwest"`;
exports[`location > 1211 > direction > with abbreviated option 1`] = `"SW"`;
-exports[`location > 1211 > direction > with boolean 1`] = `"Southwest"`;
-
exports[`location > 1211 > latitude > noArgs 1`] = `77.1337`;
-exports[`location > 1211 > latitude > with max 1`] = `2.8521`;
-
exports[`location > 1211 > latitude > with max and min option 1`] = `8.5704`;
exports[`location > 1211 > latitude > with max option 1`] = `2.8521`;
exports[`location > 1211 > latitude > with max, min and precision option 1`] = `8.5704030781`;
-exports[`location > 1211 > latitude > with min 1`] = `82.8521`;
-
exports[`location > 1211 > latitude > with min option 1`] = `82.8521`;
-exports[`location > 1211 > latitude > with precision 1`] = `77.1336277025`;
-
exports[`location > 1211 > latitude > with precision option 1`] = `77.1336277025`;
exports[`location > 1211 > longitude > noArgs 1`] = `154.2673`;
-exports[`location > 1211 > longitude > with max 1`] = `-3.5811`;
-
exports[`location > 1211 > longitude > with max and min option 1`] = `8.5704`;
exports[`location > 1211 > longitude > with max option 1`] = `-3.5811`;
exports[`location > 1211 > longitude > with max, min and precision option 1`] = `8.5704030781`;
-exports[`location > 1211 > longitude > with min 1`] = `166.4189`;
-
exports[`location > 1211 > longitude > with min option 1`] = `166.4189`;
-exports[`location > 1211 > longitude > with precision 1`] = `154.267255405`;
-
exports[`location > 1211 > longitude > with precision option 1`] = `154.267255405`;
exports[`location > 1211 > nearbyGPSCoordinate > near origin 1`] = `
@@ -292,16 +250,12 @@ exports[`location > 1211 > ordinalDirection > noArgs 1`] = `"Southwest"`;
exports[`location > 1211 > ordinalDirection > with abbreviated option 1`] = `"SW"`;
-exports[`location > 1211 > ordinalDirection > with boolean 1`] = `"Southwest"`;
-
exports[`location > 1211 > secondaryAddress 1`] = `"Suite 929"`;
exports[`location > 1211 > state > noArgs 1`] = `"Washington"`;
exports[`location > 1211 > state > with options 1`] = `"WA"`;
-exports[`location > 1211 > stateAbbr 1`] = `"WA"`;
-
exports[`location > 1211 > street 1`] = `"W Chestnut Street"`;
exports[`location > 1211 > streetAddress > noArgs 1`] = `"929 S Broad Street"`;
@@ -318,20 +272,14 @@ exports[`location > 1211 > zipCode > with format option 1`] = `"982-966"`;
exports[`location > 1211 > zipCode > with string 1`] = `"982"`;
-exports[`location > 1211 > zipCodeByState > noArgs 1`] = `"82966-7368"`;
-
exports[`location > 1337 > buildingNumber 1`] = `"22435"`;
exports[`location > 1337 > cardinalDirection > noArgs 1`] = `"East"`;
exports[`location > 1337 > cardinalDirection > with abbreviated option 1`] = `"E"`;
-exports[`location > 1337 > cardinalDirection > with boolean 1`] = `"East"`;
-
exports[`location > 1337 > city 1`] = `"East Duane"`;
-exports[`location > 1337 > cityName 1`] = `"East Hartford"`;
-
exports[`location > 1337 > country 1`] = `"Egypt"`;
exports[`location > 1337 > countryCode > noArgs 1`] = `"EH"`;
@@ -354,42 +302,28 @@ exports[`location > 1337 > direction > noArgs 1`] = `"South"`;
exports[`location > 1337 > direction > with abbreviated option 1`] = `"S"`;
-exports[`location > 1337 > direction > with boolean 1`] = `"South"`;
-
exports[`location > 1337 > latitude > noArgs 1`] = `-42.8356`;
-exports[`location > 1337 > latitude > with max 1`] = `-63.7976`;
-
exports[`location > 1337 > latitude > with max and min option 1`] = `-4.7595`;
exports[`location > 1337 > latitude > with max option 1`] = `-63.7976`;
exports[`location > 1337 > latitude > with max, min and precision option 1`] = `-4.7595064997`;
-exports[`location > 1337 > latitude > with min 1`] = `16.2024`;
-
exports[`location > 1337 > latitude > with min option 1`] = `16.2024`;
-exports[`location > 1337 > latitude > with precision 1`] = `-42.8355584972`;
-
exports[`location > 1337 > latitude > with precision option 1`] = `-42.8355584972`;
exports[`location > 1337 > longitude > noArgs 1`] = `-85.6711`;
-exports[`location > 1337 > longitude > with max 1`] = `-130.2153`;
-
exports[`location > 1337 > longitude > with max and min option 1`] = `-4.7595`;
exports[`location > 1337 > longitude > with max option 1`] = `-130.2153`;
exports[`location > 1337 > longitude > with max, min and precision option 1`] = `-4.7595064997`;
-exports[`location > 1337 > longitude > with min 1`] = `39.7847`;
-
exports[`location > 1337 > longitude > with min option 1`] = `39.7847`;
-exports[`location > 1337 > longitude > with precision 1`] = `-85.6711169944`;
-
exports[`location > 1337 > longitude > with precision option 1`] = `-85.6711169944`;
exports[`location > 1337 > nearbyGPSCoordinate > near origin 1`] = `
@@ -452,16 +386,12 @@ exports[`location > 1337 > ordinalDirection > noArgs 1`] = `"Northwest"`;
exports[`location > 1337 > ordinalDirection > with abbreviated option 1`] = `"NW"`;
-exports[`location > 1337 > ordinalDirection > with boolean 1`] = `"Northwest"`;
-
exports[`location > 1337 > secondaryAddress 1`] = `"Apt. 224"`;
exports[`location > 1337 > state > noArgs 1`] = `"Indiana"`;
exports[`location > 1337 > state > with options 1`] = `"IN"`;
-exports[`location > 1337 > stateAbbr 1`] = `"IN"`;
-
exports[`location > 1337 > street 1`] = `"Carmella Forge"`;
exports[`location > 1337 > streetAddress > noArgs 1`] = `"22435 Westley Ridges"`;
@@ -477,5 +407,3 @@ exports[`location > 1337 > zipCode > noArgs 1`] = `"12435"`;
exports[`location > 1337 > zipCode > with format option 1`] = `"212-435"`;
exports[`location > 1337 > zipCode > with string 1`] = `"212"`;
-
-exports[`location > 1337 > zipCodeByState > noArgs 1`] = `"12435"`;
diff --git a/test/modules/helpers.spec.ts b/test/modules/helpers.spec.ts
index e60859ef..98c3488a 100644
--- a/test/modules/helpers.spec.ts
+++ b/test/modules/helpers.spec.ts
@@ -152,7 +152,7 @@ describe('helpers', () => {
.it('with multiple dynamic templates', [
'{{string.sample}}',
'{{location.city_name}}',
- '{{location.cityName}}',
+ '{{location.streetAddress}}',
]);
});
@@ -989,10 +989,10 @@ describe('helpers', () => {
});
it('should be able to pass multiple dynamic templates', () => {
- expect(faker.definitions.location.city_name).toContain(
+ expect(faker.definitions.company.buzz_noun).toContain(
faker.helpers.fake([
- '{{location.city_name}}',
- '{{location.cityName}}',
+ '{{company.buzz_noun}}',
+ '{{company.buzzNoun}}',
])
);
});
@@ -1038,8 +1038,8 @@ describe('helpers', () => {
});
it('should support deprecated module aliases', () => {
- expect(faker.definitions.location.city_name).toContain(
- faker.helpers.fake('{{address.cityName}}')
+ expect(faker.definitions.location.state).toContain(
+ faker.helpers.fake('{{address.state}}')
);
expect(faker.definitions.person.first_name).toContain(
faker.helpers.fake('{{name.firstName}}')
diff --git a/test/modules/location.spec.ts b/test/modules/location.spec.ts
index 682e3441..86897ad5 100644
--- a/test/modules/location.spec.ts
+++ b/test/modules/location.spec.ts
@@ -55,9 +55,6 @@ describe('location', () => {
seededTests(faker, 'location', (t) => {
t.it('street');
- // TODO @xDivisionByZerox 2023-04-16: add street name locale data to `en`
- t.skip('streetName');
-
t.it('buildingNumber');
t.it('secondaryAddress');
@@ -68,7 +65,7 @@ describe('location', () => {
.it('with useFullAddress options', { useFullAddress: true });
});
- t.itEach('city', 'cityName');
+ t.itEach('city');
t.it('county');
@@ -89,9 +86,6 @@ describe('location', () => {
'longitude'
)((t) => {
t.it('noArgs')
- .it('with max', 10)
- .it('with min', undefined, -10)
- .it('with precision', undefined, undefined, 10)
.it('with max option', { max: 10 })
.it('with min option', { min: -10 })
.it('with precision option', { precision: 10 })
@@ -122,8 +116,6 @@ describe('location', () => {
t.it('noArgs').it('with options', { abbreviated: true });
});
- t.it('stateAbbr');
-
t.it('timeZone');
t.describeEach(
@@ -131,27 +123,17 @@ describe('location', () => {
'cardinalDirection',
'ordinalDirection'
)((t) => {
- t.it('noArgs')
- .it('with boolean', false)
- .it('with abbreviated option', { abbreviated: true });
+ t.it('noArgs').it('with abbreviated option', { abbreviated: true });
});
t.describe('zipCode', (t) => {
t.it('noArgs')
.it('with string', '###')
.it('with format option', { format: '###-###' });
- // These are currently commented out because non-default locales are currently not supported
+ // TODO @Shinigami92 2024-03-15: These are currently commented out because non-default locales are currently not supported
// .it('with state option', { state: 'CA' })
// .it('with options', { state: 'CA', format: '###-###' });
});
-
- t.describe('zipCodeByState', (t) => {
- t.it('noArgs');
- // These are currently commented out because non-default locales are currently not supported
- // .it('with string 1', 'CA')
- // .it('with string 2', 'WA')
- // .it('with state options', { state: 'WA' });
- });
});
describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))(
@@ -231,24 +213,6 @@ describe('location', () => {
});
});
- describe('zipCodeByState()', () => {
- it('returns zipCode valid for specified State', () => {
- const states = ['IL', 'GA', 'WA'];
-
- const zipCode1 = +fakerEN_US.location.zipCodeByState(states[0]);
- expect(zipCode1).toBeGreaterThanOrEqual(60001);
- expect(zipCode1).toBeLessThanOrEqual(62999);
-
- const zipCode2 = +fakerEN_US.location.zipCodeByState(states[1]);
- expect(zipCode2).toBeGreaterThanOrEqual(30001);
- expect(zipCode2).toBeLessThanOrEqual(31999);
-
- const zipCode3 = +fakerEN_US.location.zipCodeByState(states[2]);
- expect(zipCode3).toBeGreaterThanOrEqual(98001);
- expect(zipCode3).toBeLessThanOrEqual(99403);
- });
- });
-
describe('buildingNumber()', () => {
it('never starts with a zero', () => {
const buildingNumber = faker.location.buildingNumber();