From ccb58a177f2c311130b85b7a7c2efe0e0402d886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leyla=20J=C3=A4hnig?= <77127505+xDivisionByZerox@users.noreply.github.com> Date: Tue, 5 Apr 2022 18:54:19 +0200 Subject: [PATCH] refactor(address.countryCode): signature (#588) --- src/address.ts | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/address.ts b/src/address.ts index 246f4d9b455..f7ceeddc297 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]); } /**