aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
parente624d0edddfbbb6a67f3a3abfec48ac37e70b976 (diff)
downloadfaker-6dee178558b87b73bba1395c11d2ffe3d156dad1.tar.xz
faker-6dee178558b87b73bba1395c11d2ffe3d156dad1.zip
refactor(location)!: remove v8 deprecated location methods (#2753)
Diffstat (limited to 'src')
-rw-r--r--src/modules/location/index.ts842
1 files changed, 91 insertions, 751 deletions
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) {