From 5a397e0f8a6b4651a5b093b8eafe4895bf166845 Mon Sep 17 00:00:00 2001 From: Hanna <108692126+hankucz@users.noreply.github.com> Date: Mon, 1 Aug 2022 21:04:21 +0200 Subject: fix(finance.bic): remove hardcoded elements and simplify function (#1171) --- src/modules/finance/index.ts | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'src/modules') 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}`; } /** -- cgit v1.2.3