From fe97c29ef888b41582d4ad55753c7eb7e4bac6fc Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Thu, 22 Sep 2022 12:27:19 -0400 Subject: feat(finance): branch code option in bic() (#1378) --- src/modules/finance/index.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/modules') diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index c73bf6ae..b70950be 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -429,19 +429,30 @@ export class FinanceModule { /** * Generates a random SWIFT/BIC code based on the [ISO-9362](https://en.wikipedia.org/wiki/ISO_9362) format. * + * @param options Options object. + * @param options.includeBranchCode Whether to include a three-digit branch code at the end of the generated code. Defaults to a random boolean value. + * * @example - * faker.finance.bic() // 'WYAUPGX1432' + * faker.finance.bic() // 'WYAUPGX1' + * faker.finance.bic({ includeBranchCode: true }) // 'KCAUPGR1432' + * faker.finance.bic({ includeBranchCode: false }) // 'XDAFQGT7' * * @since 4.0.0 */ - bic(): string { + bic( + options: { + includeBranchCode?: boolean; + } = {} + ): string { + const { includeBranchCode = this.faker.datatype.boolean() } = options; + 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() + const branchCode = includeBranchCode ? this.faker.datatype.boolean() ? this.faker.random.alphaNumeric(3, { casing: 'upper' }) : 'XXX' -- cgit v1.2.3