diff options
| author | Hanna <[email protected]> | 2022-08-01 21:04:21 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-01 19:04:21 +0000 |
| commit | 5a397e0f8a6b4651a5b093b8eafe4895bf166845 (patch) | |
| tree | 4c965e5bc7546887fc3ec164b5b2d4d9301544a9 /src/modules | |
| parent | aafab45917ce01a3b445caff8ef3d17382535ceb (diff) | |
| download | faker-5a397e0f8a6b4651a5b093b8eafe4895bf166845.tar.xz faker-5a397e0f8a6b4651a5b093b8eafe4895bf166845.zip | |
fix(finance.bic): remove hardcoded elements and simplify function (#1171)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/finance/index.ts | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index 5d83963b..7085ea36 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -390,29 +390,25 @@ export class Finance { } /** - * Generates a random bic. + * Generates a random SWIFT/BIC code based on the [ISO-9362](https://en.wikipedia.org/wiki/ISO_9362) format. * * @example * faker.finance.bic() // 'WYAUPGX1432' */ bic(): string { - const vowels = ['A', 'E', 'I', 'O', 'U']; - const prob = this.faker.datatype.number(100); - - return [ - this.faker.helpers.replaceSymbols('???'), - this.faker.helpers.arrayElement(vowels), - this.faker.helpers.arrayElement(iban.iso3166), - this.faker.helpers.replaceSymbols('?'), - '1', - prob < 10 - ? this.faker.helpers.replaceSymbols( - `?${this.faker.helpers.arrayElement(vowels)}?` - ) - : prob < 40 - ? this.faker.helpers.replaceSymbols('###') - : '', - ].join(''); + const bankIdentifier = this.faker.random.alpha({ + count: 4, + casing: 'upper', + }); + const countryCode = this.faker.helpers.arrayElement(iban.iso3166); + const locationCode = this.faker.random.alphaNumeric(2, { casing: 'upper' }); + const branchCode = this.faker.datatype.boolean() + ? this.faker.datatype.boolean() + ? this.faker.random.alphaNumeric(3, { casing: 'upper' }) + : 'XXX' + : ''; + + return `${bankIdentifier}${countryCode}${locationCode}${branchCode}`; } /** |
