diff --git a/src/definitions/finance.ts b/src/definitions/finance.ts index 859af47a5f6..633d087f8f2 100644 --- a/src/definitions/finance.ts +++ b/src/definitions/finance.ts @@ -9,12 +9,12 @@ export interface FinanceDefinitions { */ account_type: string[]; /** - * The pattern by (lowercase) provider name used to generate credit card codes. + * The pattern by (lowercase) issuer name used to generate credit card codes. * `L` will be replaced by the check bit. * * @see Helpers.replaceCreditCardSymbols() */ - credit_card: { [provider: string]: string[] }; + credit_card: { [issuer: string]: string[] }; /** * Currencies by their full name and their symbols (e.g. `US Dollar` -> `USD` / `$`). */ diff --git a/src/finance.ts b/src/finance.ts index 1ff24ecad10..7211de3b2f8 100644 --- a/src/finance.ts +++ b/src/finance.ts @@ -245,24 +245,24 @@ export class Finance { /** * Generates a random credit card number. * - * @param provider The name of the provider (case insensitive) or the format used to generate one. + * @param issuer The name of the issuer (case insensitive) or the format used to generate one. * * @example * faker.finance.creditCardNumber() // '4427163488668' * faker.finance.creditCardNumber('visa') // '4882664999003' * faker.finance.creditCardNumber('63[7-9]#-####-####-###L') // '6375-3265-4676-6644' */ - creditCardNumber(provider = ''): string { + creditCardNumber(issuer = ''): string { let format: string; const localeFormat = this.faker.definitions.finance.credit_card; - const normalizedProvider = provider.toLowerCase(); - if (normalizedProvider in localeFormat) { - format = this.faker.random.arrayElement(localeFormat[normalizedProvider]); - } else if (provider.match(/#/)) { + const normalizedIssuer = issuer.toLowerCase(); + if (normalizedIssuer in localeFormat) { + format = this.faker.random.arrayElement(localeFormat[normalizedIssuer]); + } else if (issuer.match(/#/)) { // The user chose an optional scheme - format = provider; + format = issuer; } else { - // Choose a random provider + // Choose a random issuer // Credit cards are in an object structure const formats = this.faker.helpers.objectValue(localeFormat); // There could be multiple formats format = this.faker.random.arrayElement(formats); @@ -285,6 +285,18 @@ export class Finance { return cvv; } + /** + * Returns a random credit card issuer. + * + * @example + * faker.finance.creditCardIssuer() // 'discover' + */ + creditCardIssuer(): string { + return this.faker.helpers.objectKey( + this.faker.definitions.finance.credit_card + ) as string; + } + /** * Generates a random PIN number. * diff --git a/test/finance.spec.ts b/test/finance.spec.ts index 55e9008b23b..df5a193538f 100644 --- a/test/finance.spec.ts +++ b/test/finance.spec.ts @@ -394,7 +394,7 @@ describe('finance', () => { expect(luhnCheck(faker.finance.creditCardNumber())).toBeTruthy(); }); - it('should ignore case for provider', () => { + it('should ignore case for issuer', () => { const seed = faker.seedValue; faker.seed(seed); @@ -450,6 +450,16 @@ describe('finance', () => { }); }); + describe('creditCardIssuer()', () => { + it('should return a string', () => { + const issuer = faker.finance.creditCardIssuer(); + expect(issuer).toBeTypeOf('string'); + expect(Object.keys(faker.definitions.finance.credit_card)).toContain( + issuer + ); + }); + }); + describe('creditCardCVV()', () => { it('should return a valid credit card CVV', () => { const cvv = faker.finance.creditCardCVV();