aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLeyla Jähnig <[email protected]>2022-04-05 18:54:19 +0200
committerGitHub <[email protected]>2022-04-05 16:54:19 +0000
commitccb58a177f2c311130b85b7a7c2efe0e0402d886 (patch)
tree03f684b3d15ea0e044da2d2f4f6678068e67ac68 /src
parent307c2d20c6cafef55a10fb424e5683c0d018cc55 (diff)
downloadfaker-ccb58a177f2c311130b85b7a7c2efe0e0402d886.tar.xz
faker-ccb58a177f2c311130b85b7a7c2efe0e0402d886.zip
refactor(address.countryCode): signature (#588)
Diffstat (limited to 'src')
-rw-r--r--src/address.ts21
1 files changed, 4 insertions, 17 deletions
diff --git a/src/address.ts b/src/address.ts
index 246f4d9b..f7ceeddc 100644
--- a/src/address.ts
+++ b/src/address.ts
@@ -340,25 +340,12 @@ export class Address {
* faker.address.countryCode() // 'SJ'
* faker.address.countryCode('alpha-2') // 'GA'
* faker.address.countryCode('alpha-3') // 'TJK'
- * faker.address.countryCode('unsupported') // 'DJ'
*/
- // TODO ST-DDT 2022-02-10: Limit the parameter to the two values.
- countryCode(alphaCode: string = 'alpha-2'): string {
- if (alphaCode === 'alpha-2') {
- return this.faker.random.arrayElement(
- this.faker.definitions.address.country_code
- );
- }
+ countryCode(alphaCode: 'alpha-2' | 'alpha-3' = 'alpha-2'): string {
+ const key: keyof typeof this.faker.definitions.address =
+ alphaCode === 'alpha-3' ? 'country_code_alpha_3' : 'country_code';
- if (alphaCode === 'alpha-3') {
- return this.faker.random.arrayElement(
- this.faker.definitions.address.country_code_alpha_3
- );
- }
-
- return this.faker.random.arrayElement(
- this.faker.definitions.address.country_code
- );
+ return this.faker.random.arrayElement(this.faker.definitions.address[key]);
}
/**