diff options
| author | DivisionByZero <[email protected]> | 2023-04-17 15:24:50 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-17 13:24:50 +0000 |
| commit | 5c8638b99c2f8cf4e207322bd048bec2724a4dc1 (patch) | |
| tree | 90c5b0c9909d4167370e20e1089573def21580a8 /src | |
| parent | bb9e0e3d8528caf26e84b6ca12436b5c38ba1a18 (diff) | |
| download | faker-5c8638b99c2f8cf4e207322bd048bec2724a4dc1.tar.xz faker-5c8638b99c2f8cf4e207322bd048bec2724a4dc1.zip | |
refactor(location): merge state and stateAbbr (#2060)
Diffstat (limited to 'src')
| -rw-r--r-- | src/modules/location/index.ts | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts index 4931d46f..1d0bd4a4 100644 --- a/src/modules/location/index.ts +++ b/src/modules/location/index.ts @@ -338,17 +338,35 @@ export class LocationModule { /** * Returns a random localized state, or other equivalent first-level administrative entity for the locale's country such as a province or region. * + * @param options An options object. Defaults to `{}`. + * @param options.abbreviated If true this will return abbreviated first-level administrative entity names. + * Otherwise this will return the long name. Defaults to `false`. + * * @example * faker.location.state() // 'Mississippi' * fakerEN_CA.location.state() // 'Saskatchewan' * fakerDE.location.state() // 'Nordrhein-Westfalen' + * faker.location.state({ abbreviated: true }) // 'LA' * * @since 8.0.0 */ - state(): string { - return this.faker.helpers.arrayElement( - this.faker.definitions.location.state - ); + state( + options: { + /** + * If true this will return abbreviated first-level administrative entity names. + * Otherwise this will return the long name. + * + * @default false + */ + abbreviated?: boolean; + } = {} + ): string { + const { abbreviated = false } = options; + const stateDataSet = abbreviated + ? this.faker.definitions.location.state_abbr + : this.faker.definitions.location.state; + + return this.faker.helpers.arrayElement(stateDataSet); } /** @@ -358,11 +376,17 @@ export class LocationModule { * faker.location.stateAbbr() // 'ND' * * @since 8.0.0 + * + * @deprecated Use `faker.location.state({ abbreviated: true })` instead. */ stateAbbr(): string { - return this.faker.helpers.arrayElement( - this.faker.definitions.location.state_abbr - ); + deprecated({ + deprecated: 'faker.location.stateAbbr()', + proposed: 'faker.location.state({ abbreviated: true })', + since: '8.0', + until: '9.0', + }); + return this.state({ abbreviated: true }); } /** |
