Skip to content

Commit

Permalink
refactor(address.countryCode): signature (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
xDivisionByZerox authored Apr 5, 2022
1 parent 307c2d2 commit ccb58a1
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

/**
Expand Down

0 comments on commit ccb58a1

Please sign in to comment.