diff options
| author | DivisionByZero <[email protected]> | 2023-02-15 10:14:49 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-15 09:14:49 +0000 |
| commit | 1399375686afb99a4ea55a6153601905f395304d (patch) | |
| tree | 2501785322b7663d5e5bfb18ff445e00a748a3cd | |
| parent | 8f2d5c8a6d5c733e0dde6efdd3a5e058d372ee07 (diff) | |
| download | faker-1399375686afb99a4ea55a6153601905f395304d.tar.xz faker-1399375686afb99a4ea55a6153601905f395304d.zip | |
refactor(finance): standardize arguments (#1821)
| -rw-r--r-- | src/modules/finance/index.ts | 685 | ||||
| -rw-r--r-- | test/__snapshots__/finance.spec.ts.snap | 114 | ||||
| -rw-r--r-- | test/finance.spec.ts | 72 |
3 files changed, 827 insertions, 44 deletions
diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index 8a8d91d2..d137ee1b 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -28,8 +28,86 @@ export class FinanceModule { * * @since 2.0.1 */ - account(length?: number): string { - length = length || 8; + account(length?: number): string; + /** + * Generates a random account number. + * + * @param options An options object. Defaults to `{}`. + * @param options.length The length of the account number. Defaults to `8`. + * + * @example + * faker.finance.account() // 92842238 + * faker.finance.account({ length: 5 }) // 32564 + * + * @since 2.0.1 + */ + account(options?: { + /** + * The length of the account number. + * + * @default 8 + */ + length?: number; + }): string; + /** + * Generates a random account number. + * + * @param optionsOrLength An options object or the length of the account number. Defaults to `{}`. + * @param optionsOrLength.length The length of the account number. Defaults to `8`. + * + * @example + * faker.finance.account() // 92842238 + * faker.finance.account(5) // 28736 + * faker.finance.account({ length: 5 }) // 32564 + * + * @since 2.0.1 + */ + account( + optionsOrLength?: + | number + | { + /** + * The length of the account number. + * + * @default 8 + */ + length?: number; + } + ): string; + /** + * Generates a random account number. + * + * @param options An options object or the length of the account number. Defaults to `{}`. + * @param options.length The length of the account number. Defaults to `8`. + * + * @example + * faker.finance.account() // 92842238 + * faker.finance.account(5) // 28736 + * faker.finance.account({ length: 5 }) // 32564 + * + * @since 2.0.1 + */ + account( + options: + | number + | { + /** + * The length of the account number. + * + * @default 8 + */ + length?: number; + } = {} + ): string { + if (typeof options === 'number') { + options = { length: options }; + } + + let { length = 8 } = options; + if (length === 0) { + length = 8; + } + let template = ''; for (let i = 0; i < length; i++) { @@ -96,11 +174,129 @@ export class FinanceModule { * * @since 2.0.1 */ - mask(length?: number, parens?: boolean, ellipsis?: boolean): string { + mask(length?: number, parens?: boolean, ellipsis?: boolean): string; + /** + * Generates a random masked number. + * + * @param options An options object. Defaults to `{}`. + * @param options.length The length of the unmasked number. Defaults to `4`. + * @param options.parens Whether to use surrounding parenthesis. Defaults to `true`. + * @param options.ellipsis Whether to prefix the numbers with an ellipsis. Defaults to `true`. + * + * @example + * faker.finance.mask() // '(...9711)' + * faker.finance.mask({ length: 3 }) // '(...342)' + * faker.finance.mask({ length: 3, parens: false }) // '...236' + * faker.finance.mask({ length: 3, parens: false, ellipsis: false }) // '298' + * + * @since 2.0.1 + */ + mask(options?: { + length?: number; + parens?: boolean; + ellipsis?: boolean; + }): string; + /** + * Generates a random masked number. + * + * @param optionsOrLength An options object or the length of the unmask number. Defaults to `{}`. + * @param optionsOrLength.length The length of the unmasked number. Defaults to `4`. + * @param optionsOrLength.parens Whether to use surrounding parenthesis. Defaults to `true`. + * @param optionsOrLength.ellipsis Whether to prefix the numbers with an ellipsis. Defaults to `true`. + * @param legacyParens Whether to use surrounding parenthesis. Defaults to `true`. + * @param legacyEllipsis Whether to prefix the numbers with an ellipsis. Defaults to `true`. + * + * @example + * faker.finance.mask() // '(...9711)' + * faker.finance.mask({ length: 3 }) // '(...342)' + * faker.finance.mask({ length: 3, parens: false }) // '...236' + * faker.finance.mask({ length: 3, parens: false, ellipsis: false }) // '298' + * faker.finance.mask(3) // '(...342)' + * faker.finance.mask(3, false) // '...236' + * faker.finance.mask(3, false, false) // '298' + * + * @since 2.0.1 + */ + mask( + optionsOrLength?: + | number + | { + /** + * The length of the unmasked number. + * + * @default 4 + */ + length?: number; + /** + * Whether to use surrounding parenthesis. + * + * @default true + */ + parens?: boolean; + /** + * Whether to prefix the numbers with an ellipsis. + * + * @default true + */ + ellipsis?: boolean; + }, + legacyParens?: boolean, + legacyEllipsis?: boolean + ): string; + /** + * Generates a random masked number. + * + * @param options An options object. Defaults to `{}`. + * @param options.length The length of the unmasked number. Defaults to `4`. + * @param options.parens Whether to use surrounding parenthesis. Defaults to `true`. + * @param options.ellipsis Whether to prefix the numbers with an ellipsis. Defaults to `true`. + * @param legacyParens Whether to use surrounding parenthesis. Defaults to `true`. + * @param legacyEllipsis Whether to use surrounding parenthesis. Defaults to `true`. + * + * @example + * faker.finance.mask() // '(...9711)' + * faker.finance.mask(3) // '(...342)' + * faker.finance.mask(3, false) // '...236' + * faker.finance.mask(3, false, false) // '298' + * + * @since 2.0.1 + */ + mask( + options: + | number + | { + /** + * The length of the unmasked number. + * + * @default 4 + */ + length?: number; + /** + * Whether to use surrounding parenthesis. + * + * @default true + */ + parens?: boolean; + /** + * Whether to prefix the numbers with an ellipsis. + * + * @default true + */ + ellipsis?: boolean; + } = {}, + legacyParens: boolean = true, + legacyEllipsis: boolean = true + ): string { + if (typeof options === 'number') { + options = { length: options }; + } + // set defaults - length = length || 4; - parens = parens == null ? true : parens; - ellipsis = ellipsis == null ? true : ellipsis; + const { + ellipsis = legacyEllipsis, + length = 4, + parens = legacyParens, + } = options; // create a template for length let template = ''; @@ -139,12 +335,209 @@ export class FinanceModule { * @since 2.0.1 */ amount( - min: number = 0, - max: number = 1000, - dec: number = 2, - symbol: string = '', + min?: number, + max?: number, + dec?: number, + symbol?: string, autoFormat?: boolean + ): string; + /** + * Generates a random amount between the given bounds (inclusive). + * + * @param options An options object. Defaults to `{}`. + * @param options.min The lower bound for the amount. Defaults to `0`. + * @param options.max The upper bound for the amount. Defaults to `1000`. + * @param options.dec The number of decimal places for the amount. Defaults to `2`. + * @param options.symbol The symbol used to prefix the amount. Defaults to `''`. + * @param options.autoFormat If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. + * + * @example + * faker.finance.amount() // '617.87' + * faker.finance.amount({ min: 5, max: 10 }) // '5.53' + * faker.finance.amount({ min: 5, max: 10, dec: 0 }) // '8' + * faker.finance.amount({ min: 5, max: 10, dec: 2, symbol: '$' }) // '$5.85' + * faker.finance.amount({ min: 5, max: 10, dec: 5, symbol: '', autoFormat: true }) // '9,75067' + * + * @since 2.0.1 + */ + amount(options?: { + /** + * The lower bound for the amount. + * + * @default 0 + */ + min?: number; + /** + * The upper bound for the amount. + * + * @default 1000 + */ + max?: number; + /** + * The number of decimal places for the amount. + * + * @default 2 + */ + dec?: number; + /** + * The symbol used to prefix the amount. + * + * @default '' + */ + symbol?: string; + /** + * If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. + * + * @default false + */ + autoFormat?: boolean; + }): string; + /** + * Generates a random amount between the given bounds (inclusive). + * + * @param options An options object. Defaults to `{}`. + * @param options.min The lower bound for the amount. Defaults to `0`. + * @param options.max The upper bound for the amount. Defaults to `1000`. + * @param options.dec The number of decimal places for the amount. Defaults to `2`. + * @param options.symbol The symbol used to prefix the amount. Defaults to `''`. + * @param options.autoFormat If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. + * @param legacyMax The upper bound for the amount. Defaults to `1000`. + * @param legacyDec The number of decimal places for the amount. Defaults to `2`. + * @param legacySymbol The symbol used to prefix the amount. Defaults to `''`. + * @param legacyAutoFormat If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. + * + * @example + * faker.finance.amount() // '617.87' + * faker.finance.amount({ min: 5, max: 10 }) // '5.53' + * faker.finance.amount({ min: 5, max: 10, dec: 0 }) // '8' + * faker.finance.amount({ min: 5, max: 10, dec: 2, symbol: '$' }) // '$5.85' + * faker.finance.amount({ min: 5, max: 10, dec: 5, symbol: '', autoFormat: true }) // '9,75067' + * faker.finance.amount(5, 10) // '5.53' + * faker.finance.amount(5, 10, 0) // '8' + * faker.finance.amount(5, 10, 2, '$') // '$5.85' + * faker.finance.amount(5, 10, 5, '', true) // '9,75067' + * + * @since 2.0.1 + */ + amount( + options?: + | number + | { + /** + * The lower bound for the amount. + * + * @default 0 + */ + min?: number; + /** + * The upper bound for the amount. + * + * @default 1000 + */ + max?: number; + /** + * The number of decimal places for the amount. + * + * @default 2 + */ + dec?: number; + /** + * The symbol used to prefix the amount. + * + * @default '' + */ + symbol?: string; + /** + * If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. + * + * @default false + */ + autoFormat?: boolean; + }, + legacyMax?: number, + legacyDec?: number, + legacySymbol?: string, + legacyAutoFormat?: boolean + ): string; + /** + * Generates a random amount between the given bounds (inclusive). + * + * @param options An options object. Defaults to `{}`. + * @param options.min The lower bound for the amount. Defaults to `0`. + * @param options.max The upper bound for the amount. Defaults to `1000`. + * @param options.dec The number of decimal places for the amount. Defaults to `2`. + * @param options.symbol The symbol used to prefix the amount. Defaults to `''`. + * @param options.autoFormat If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. + * @param legacyMax The upper bound for the amount. Defaults to `1000`. + * @param legacyDec The number of decimal places for the amount. Defaults to `2`. + * @param legacySymbol The symbol used to prefix the amount. Defaults to `''`. + * @param legacyAutoFormat If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. + * + * @example + * faker.finance.amount() // '617.87' + * faker.finance.amount({ min: 5, max: 10 }) // '5.53' + * faker.finance.amount({ min: 5, max: 10, dec: 0 }) // '8' + * faker.finance.amount({ min: 5, max: 10, dec: 2, symbol: '$' }) // '$5.85' + * faker.finance.amount({ min: 5, max: 10, dec: 5, symbol: '', autoFormat: true }) // '9,75067' + * faker.finance.amount(5, 10) // '5.53' + * faker.finance.amount(5, 10, 0) // '8' + * faker.finance.amount(5, 10, 2, '$') // '$5.85' + * faker.finance.amount(5, 10, 5, '', true) // '9,75067' + * + * @since 2.0.1 + */ + amount( + options: + | number + | { + /** + * The lower bound for the amount. + * + * @default 0 + */ + min?: number; + /** + * The upper bound for the amount. + * + * @default 1000 + */ + max?: number; + /** + * The number of decimal places for the amount. + * + * @default 2 + */ + dec?: number; + /** + * The symbol used to prefix the amount. + * + * @default '' + */ + symbol?: string; + /** + * If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. + * + * @default false + */ + autoFormat?: boolean; + } = {}, + legacyMax: number = 1000, + legacyDec: number = 2, + legacySymbol: string = '', + legacyAutoFormat: boolean = false ): string { + if (typeof options === 'number') { + options = { min: options }; + } + + const { + autoFormat = legacyAutoFormat, + dec = legacyDec, + max = legacyMax, + min = 0, + symbol = legacySymbol, + } = options; + const randValue = this.faker.number.float({ max, min, @@ -280,7 +673,86 @@ export class FinanceModule { * * @since 5.0.0 */ - creditCardNumber(issuer = ''): string { + creditCardNumber(issuer?: string): string; + /** + * Generates a random credit card number. + * + * @param options An options object. Defaults to `''`. + * @param options.issuer The name of the issuer (case insensitive) or the format used to generate one. + * + * @example + * faker.finance.creditCardNumber() // '4427163488662' + * faker.finance.creditCardNumber({ issuer: 'visa' }) // '4882664999007' + * faker.finance.creditCardNumber({ issuer: '63[7-9]#-####-####-###L' }) // '6375-3265-4676-6646' + * + * @since 5.0.0 + */ + creditCardNumber(options?: { + /** + * The name of the issuer (case insensitive) or the format used to generate one. + * + * @default '' + */ + issuer?: string; + }): string; + /** + * Generates a random credit card number. + * + * @param options An options object, the issuer or a custom format. Defaults to `{}`. + * @param options.issuer The name of the issuer (case insensitive) or the format used to generate one. + * + * @example + * faker.finance.creditCardNumber() // '4427163488662' + * faker.finance.creditCardNumber({ issuer: 'visa' }) // '4882664999007' + * faker.finance.creditCardNumber({ issuer: '63[7-9]#-####-####-###L' }) // '6375-3265-4676-6646' + * faker.finance.creditCardNumber('visa') // '1226423499765' + * + * @since 5.0.0 + */ + creditCardNumber( + options?: + | string + | { + /** + * The name of the issuer (case insensitive) or the format used to generate one. + * + * @default '' + */ + issuer?: string; + } + ): string; + /** + * Generates a random credit card number. + * + * @param options An options object, the issuer or a custom format. Defaults to `{}`. + * @param options.issuer The name of the issuer (case insensitive) or the format used to generate one. + * + * @example + * faker.finance.creditCardNumber() // '4427163488662' + * faker.finance.creditCardNumber({ issuer: 'visa' }) // '4882664999007' + * faker.finance.creditCardNumber({ issuer: '63[7-9]#-####-####-###L' }) // '6375-3265-4676-6646' + * faker.finance.creditCardNumber('visa') // '1226423499765' + * + * @since 5.0.0 + */ + creditCardNumber( + options: + | string + | { + /** + * The name of the issuer (case insensitive) or the format used to generate one. + * + * @default '' + */ + issuer?: string; + } = {} + ): string { + if (typeof options === 'string') { + options = { issuer: options }; + } + + const { issuer = '' } = options; + let format: string; const localeFormat = this.faker.definitions.finance.credit_card; const normalizedIssuer = issuer.toLowerCase(); @@ -338,7 +810,86 @@ export class FinanceModule { * * @since 6.2.0 */ - pin(length: number = 4): string { + pin(length?: number): string; + /** + * Generates a random PIN number. + * + * @param options An options object. Defaults to `{}`. + * @param options.length The length of the PIN to generate. Defaults to `4`. + * @throws Will throw an error if length is less than 1. + * + * @example + * faker.finance.pin() // '5067' + * faker.finance.pin({ length: 6 }) // '213789' + * + * @since 6.2.0 + */ + pin(options?: { + /** + * The length of the PIN to generate. + * + * @default 4 + */ + length?: number; + }): string; + /** + * Generates a random PIN number. + * + * @param options An options object or the length of the PIN. Defaults to `{}`. + * @param options.length The length of the PIN to generate. Defaults to `4`. + * @throws Will throw an error if length is less than 1. + * + * @example + * faker.finance.pin() // '5067' + * faker.finance.pin({ length: 6 }) // '213789' + * faker.finance.pin(6) // '213789' + * + * @since 6.2.0 + */ + pin( + options?: + | number + | { + /** + * The length of the PIN to generate. + * + * @default 4 + */ + length?: number; + } + ): string; + /** + * Generates a random PIN number. + * + * @param options An options object or the length of the PIN. Defaults to `{}`. + * @param options.length The length of the PIN to generate. Defaults to `4`. + * @throws Will throw an error if length is less than 1. + * + * @example + * faker.finance.pin() // '5067' + * faker.finance.pin({ length: 6 }) // '213789' + * faker.finance.pin(6) // '213789' + * + * @since 6.2.0 + */ + pin( + options: + | number + | { + /** + * The length of the PIN to generate. + * + * @default 4 + */ + length?: number; + } = {} + ): string { + if (typeof options === 'number') { + options = { length: options }; + } + + const { length = 4 } = options; + if (length < 1) { throw new FakerError('minimum length is 1'); } @@ -378,7 +929,115 @@ export class FinanceModule { * * @since 4.0.0 */ - iban(formatted: boolean = false, countryCode?: string): string { + iban(formatted?: boolean, countryCode?: string): string; + /** + * Generates a random iban. + * + * @param options An options object. Defaults to `{}`. + * @param options.formatted Return a formatted version of the generated IBAN. Defaults to `false`. + * @param options.countryCode The country code from which you want to generate an IBAN, if none is provided a random country will be used. + * @throws Will throw an error if the passed country code is not supported. + * + * @example + * faker.finance.iban() // 'TR736918640040966092800056' + * faker.finance.iban({ formatted: true }) // 'FR20 8008 2330 8984 74S3 Z620 224' + * faker.finance.iban({ formatted: true, countryCode: 'DE' }) // 'DE84 1022 7075 0900 1170 01' + * + * @since 4.0.0 + */ + iban(options?: { + /** + * Return a formatted version of the generated IBAN. + * + * @default false + */ + formatted?: boolean; + /** + * The country code from which you want to generate an IBAN, + * if none is provided a random country will be used. + */ + countryCode?: string; + }): string; + /** + * Generates a random iban. + * + * @param options An options object or whether the return value should be formatted. Defaults to `{}`. + * @param options.formatted Return a formatted version of the generated IBAN. Defaults to `false`. + * @param options.countryCode The country code from which you want to generate an IBAN, if none is provided a random country will be used. + * @param legacyCountryCode The country code from which you want to generate an IBAN, if none is provided a random country will be used. + * + * @throws Will throw an error if the passed country code is not supported. + * + * @example + * faker.finance.iban() // 'TR736918640040966092800056' + * faker.finance.iban({ formatted: true }) // 'FR20 8008 2330 8984 74S3 Z620 224' + * faker.finance.iban({ formatted: true, countryCode: 'DE' }) // 'DE84 1022 7075 0900 1170 01' + * faker.finance.iban(true) // 'FR20 8008 2330 8984 74S3 Z620 224' + * faker.finance.iban(true, 'DE') // 'DE84 1022 7075 0900 1170 01' + * + * @since 4.0.0 + */ + iban( + options?: + | boolean + | { + /** + * Return a formatted version of the generated IBAN. + * + * @default false + */ + formatted?: boolean; + /** + * The country code from which you want to generate an IBAN, + * if none is provided a random country will be used. + */ + countryCode?: string; + }, + legacyCountryCode?: string + ): string; + /** + * Generates a random iban. + * + * @param options An options object or whether the return value should be formatted. Defaults to `{}`. + * @param options.formatted Return a formatted version of the generated IBAN. Defaults to `false`. + * @param options.countryCode The country code from which you want to generate an IBAN, if none is provided a random country will be used. + * @param legacyCountryCode The country code from which you want to generate an IBAN, if none is provided a random country will be used. + * + * @throws Will throw an error if the passed country code is not supported. + * + * @example + * faker.finance.iban() // 'TR736918640040966092800056' + * faker.finance.iban({ formatted: true }) // 'FR20 8008 2330 8984 74S3 Z620 224' + * faker.finance.iban({ formatted: true, countryCode: 'DE' }) // 'DE84 1022 7075 0900 1170 01' + * faker.finance.iban(true) // 'FR20 8008 2330 8984 74S3 Z620 224' + * faker.finance.iban(true, 'DE') // 'DE84 1022 7075 0900 1170 01' + * + * @since 4.0.0 + */ + iban( + options: + | boolean + | { + /** + * Return a formatted version of the generated IBAN. + * + * @default false + */ + formatted?: boolean; + /** + * The country code from which you want to generate an IBAN, + * if none is provided a random country will be used. + */ + countryCode?: string; + } = {}, + legacyCountryCode?: string + ): string { + if (typeof options === 'boolean') { + options = { formatted: options }; + } + + const { countryCode = legacyCountryCode, formatted = false } = options; + const ibanFormat = countryCode ? iban.formats.find((f) => f.country === countryCode) : this.faker.helpers.arrayElement(iban.formats); diff --git a/test/__snapshots__/finance.spec.ts.snap b/test/__snapshots__/finance.spec.ts.snap index 937b84ef..e3736cc8 100644 --- a/test/__snapshots__/finance.spec.ts.snap +++ b/test/__snapshots__/finance.spec.ts.snap @@ -4,17 +4,29 @@ exports[`finance > 42 > account > noArgs 1`] = `"37917755"`; exports[`finance > 42 > account > with length 1`] = `"3791775514"`; +exports[`finance > 42 > account > with length option 1`] = `"3791775514"`; + exports[`finance > 42 > accountName 1`] = `"Money Market Account"`; exports[`finance > 42 > amount > noArgs 1`] = `"374.54"`; -exports[`finance > 42 > amount > with dec 1`] = `"374.54011"`; +exports[`finance > 42 > amount > with leagcy dec 1`] = `"374.54011"`; -exports[`finance > 42 > amount > with max 1`] = `"18.73"`; +exports[`finance > 42 > amount > with leagcy max 1`] = `"18.73"`; exports[`finance > 42 > amount > with min 1`] = `"380.79"`; -exports[`finance > 42 > amount > with min and max and dec and symbol 1`] = `"$24.98161"`; +exports[`finance > 42 > amount > with min and max option 1`] = `"24.98"`; + +exports[`finance > 42 > amount > with min option 1`] = `"380.79"`; + +exports[`finance > 42 > amount > with min, leagcy max, leagcy dec and leagcy symbol 1`] = `"$24.98161"`; + +exports[`finance > 42 > amount > with min, max and dec option 1`] = `"24.98161"`; + +exports[`finance > 42 > amount > with min, max, dec and symbol option 1`] = `"#24.98161"`; + +exports[`finance > 42 > amount > with min, max, dec, symbol and autoFormat option 1`] = `"#24.98161"`; exports[`finance > 42 > bic > noArgs 1`] = `"UYETSCLLG53"`; @@ -30,6 +42,8 @@ exports[`finance > 42 > creditCardNumber > noArgs 1`] = `"3581-7755-1410-0484"`; exports[`finance > 42 > creditCardNumber > with issuer 1`] = `"4791775514102"`; +exports[`finance > 42 > creditCardNumber > with issuer option 1`] = `"4791775514102"`; + exports[`finance > 42 > currencyCode 1`] = `"IQD"`; exports[`finance > 42 > currencyName 1`] = `"Iraqi Dinar"`; @@ -44,22 +58,34 @@ exports[`finance > 42 > iban > with formatted 1`] = `"GT03 9751 1086 7098 F1E3 5 exports[`finance > 42 > iban > with formatted and countryCode 1`] = `"DE47 7175 0020 0086 0600 97"`; +exports[`finance > 42 > iban > with formatted and countryCode option 1`] = `"DE47 7175 0020 0086 0600 97"`; + +exports[`finance > 42 > iban > with formatted option 1`] = `"GT03 9751 1086 7098 F1E3 5426 12J4"`; + exports[`finance > 42 > litecoinAddress 1`] = `"3XbJMAAara64sSkA9HD24YHQWd1b"`; exports[`finance > 42 > mask > noArgs 1`] = `"(...3791)"`; -exports[`finance > 42 > mask > with ellipsis 1`] = `"(...3791)"`; +exports[`finance > 42 > mask > with legacy ellipsis 1`] = `"(...3791)"`; + +exports[`finance > 42 > mask > with legacy parenthesis 1`] = `"(...3791)"`; exports[`finance > 42 > mask > with length 1`] = `"(...37917)"`; -exports[`finance > 42 > mask > with length, parenthesis, and ellipsis 1`] = `"(...37917)"`; +exports[`finance > 42 > mask > with length and parenthesis option 1`] = `"...37917"`; -exports[`finance > 42 > mask > with parenthesis 1`] = `"(...3791)"`; +exports[`finance > 42 > mask > with length option 1`] = `"(...37917)"`; + +exports[`finance > 42 > mask > with length, legacy parenthesis, and legacy ellipsis 1`] = `"(...37917)"`; + +exports[`finance > 42 > mask > with length, parenthesis and ellipsis option 1`] = `"...37917"`; exports[`finance > 42 > pin > noArgs 1`] = `"3791"`; exports[`finance > 42 > pin > with length 1`] = `"3791775514"`; +exports[`finance > 42 > pin > with length option 1`] = `"3791775514"`; + exports[`finance > 42 > routingNumber 1`] = `"379177554"`; exports[`finance > 42 > transactionDescription 1`] = `"invoice transaction at Wiegand, Deckow and Reynolds using card ending with ***(...8361) for SDG 374.54 in account ***55141004"`; @@ -70,17 +96,29 @@ exports[`finance > 1211 > account > noArgs 1`] = `"94872190"`; exports[`finance > 1211 > account > with length 1`] = `"9487219061"`; +exports[`finance > 1211 > account > with length option 1`] = `"9487219061"`; + exports[`finance > 1211 > accountName 1`] = `"Personal Loan Account"`; exports[`finance > 1211 > amount > noArgs 1`] = `"928.52"`; -exports[`finance > 1211 > amount > with dec 1`] = `"928.52016"`; +exports[`finance > 1211 > amount > with leagcy dec 1`] = `"928.52016"`; -exports[`finance > 1211 > amount > with max 1`] = `"46.43"`; +exports[`finance > 1211 > amount > with leagcy max 1`] = `"46.43"`; exports[`finance > 1211 > amount > with min 1`] = `"929.24"`; -exports[`finance > 1211 > amount > with min and max and dec and symbol 1`] = `"$47.14081"`; +exports[`finance > 1211 > amount > with min and max option 1`] = `"47.15"`; + +exports[`finance > 1211 > amount > with min option 1`] = `"929.24"`; + +exports[`finance > 1211 > amount > with min, leagcy max, leagcy dec and leagcy symbol 1`] = `"$47.14081"`; + +exports[`finance > 1211 > amount > with min, max and dec option 1`] = `"47.14081"`; + +exports[`finance > 1211 > amount > with min, max, dec and symbol option 1`] = `"#47.14081"`; + +exports[`finance > 1211 > amount > with min, max, dec, symbol and autoFormat option 1`] = `"#47.14081"`; exports[`finance > 1211 > bic > noArgs 1`] = `"LXUFBTZ1"`; @@ -96,6 +134,8 @@ exports[`finance > 1211 > creditCardNumber > noArgs 1`] = `"4872190616274"`; exports[`finance > 1211 > creditCardNumber > with issuer 1`] = `"4487-2190-6162-7436"`; +exports[`finance > 1211 > creditCardNumber > with issuer option 1`] = `"4487-2190-6162-7436"`; + exports[`finance > 1211 > currencyCode 1`] = `"XDR"`; exports[`finance > 1211 > currencyName 1`] = `"SDR"`; @@ -110,22 +150,34 @@ exports[`finance > 1211 > iban > with formatted 1`] = `"TN42 8201 6024 1706 7929 exports[`finance > 1211 > iban > with formatted and countryCode 1`] = `"DE41 4700 9026 0417 0679 42"`; +exports[`finance > 1211 > iban > with formatted and countryCode option 1`] = `"DE41 4700 9026 0417 0679 42"`; + +exports[`finance > 1211 > iban > with formatted option 1`] = `"TN42 8201 6024 1706 7929 9006"`; + exports[`finance > 1211 > litecoinAddress 1`] = `"MTMe8Z3EaFdLqmaGKP1LEEJQVriSZRZds"`; exports[`finance > 1211 > mask > noArgs 1`] = `"(...9487)"`; -exports[`finance > 1211 > mask > with ellipsis 1`] = `"(...9487)"`; +exports[`finance > 1211 > mask > with legacy ellipsis 1`] = `"(...9487)"`; + +exports[`finance > 1211 > mask > with legacy parenthesis 1`] = `"(...9487)"`; exports[`finance > 1211 > mask > with length 1`] = `"(...94872)"`; -exports[`finance > 1211 > mask > with length, parenthesis, and ellipsis 1`] = `"(...94872)"`; +exports[`finance > 1211 > mask > with length and parenthesis option 1`] = `"...94872"`; + +exports[`finance > 1211 > mask > with length option 1`] = `"(...94872)"`; + +exports[`finance > 1211 > mask > with length, legacy parenthesis, and legacy ellipsis 1`] = `"(...94872)"`; -exports[`finance > 1211 > mask > with parenthesis 1`] = `"(...9487)"`; +exports[`finance > 1211 > mask > with length, parenthesis and ellipsis option 1`] = `"...94872"`; exports[`finance > 1211 > pin > noArgs 1`] = `"9487"`; exports[`finance > 1211 > pin > with length 1`] = `"9487219061"`; +exports[`finance > 1211 > pin > with length option 1`] = `"9487219061"`; + exports[`finance > 1211 > routingNumber 1`] = `"948721904"`; exports[`finance > 1211 > transactionDescription 1`] = `"deposit transaction at Trantow - Satterfield using card ending with ***(...4316) for STN 928.52 in account ***19061627"`; @@ -136,17 +188,29 @@ exports[`finance > 1337 > account > noArgs 1`] = `"25122540"`; exports[`finance > 1337 > account > with length 1`] = `"2512254032"`; +exports[`finance > 1337 > account > with length option 1`] = `"2512254032"`; + exports[`finance > 1337 > accountName 1`] = `"Money Market Account"`; exports[`finance > 1337 > amount > noArgs 1`] = `"262.02"`; -exports[`finance > 1337 > amount > with dec 1`] = `"262.02467"`; +exports[`finance > 1337 > amount > with leagcy dec 1`] = `"262.02467"`; -exports[`finance > 1337 > amount > with max 1`] = `"13.10"`; +exports[`finance > 1337 > amount > with leagcy max 1`] = `"13.10"`; exports[`finance > 1337 > amount > with min 1`] = `"269.40"`; -exports[`finance > 1337 > amount > with min and max and dec and symbol 1`] = `"$20.48099"`; +exports[`finance > 1337 > amount > with min and max option 1`] = `"20.48"`; + +exports[`finance > 1337 > amount > with min option 1`] = `"269.40"`; + +exports[`finance > 1337 > amount > with min, leagcy max, leagcy dec and leagcy symbol 1`] = `"$20.48099"`; + +exports[`finance > 1337 > amount > with min, max and dec option 1`] = `"20.48099"`; + +exports[`finance > 1337 > amount > with min, max, dec and symbol option 1`] = `"#20.48099"`; + +exports[`finance > 1337 > amount > with min, max, dec, symbol and autoFormat option 1`] = `"#20.48099"`; exports[`finance > 1337 > bic > noArgs 1`] = `"OEFHLYG18IL"`; @@ -162,6 +226,8 @@ exports[`finance > 1337 > creditCardNumber > noArgs 1`] = `"6011-6212-2540-3255- exports[`finance > 1337 > creditCardNumber > with issuer 1`] = `"4512254032550"`; +exports[`finance > 1337 > creditCardNumber > with issuer option 1`] = `"4512254032550"`; + exports[`finance > 1337 > currencyCode 1`] = `"FJD"`; exports[`finance > 1337 > currencyName 1`] = `"Fiji Dollar"`; @@ -176,22 +242,34 @@ exports[`finance > 1337 > iban > with formatted 1`] = `"FO56 1005 0250 0903 18"` exports[`finance > 1337 > iban > with formatted and countryCode 1`] = `"DE04 0200 5032 5009 0304 06"`; +exports[`finance > 1337 > iban > with formatted and countryCode option 1`] = `"DE04 0200 5032 5009 0304 06"`; + +exports[`finance > 1337 > iban > with formatted option 1`] = `"FO56 1005 0250 0903 18"`; + exports[`finance > 1337 > litecoinAddress 1`] = `"Madhxs2jewAgkYgJi7No6Cn8JZar"`; exports[`finance > 1337 > mask > noArgs 1`] = `"(...2512)"`; -exports[`finance > 1337 > mask > with ellipsis 1`] = `"(...2512)"`; +exports[`finance > 1337 > mask > with legacy ellipsis 1`] = `"(...2512)"`; + +exports[`finance > 1337 > mask > with legacy parenthesis 1`] = `"(...2512)"`; exports[`finance > 1337 > mask > with length 1`] = `"(...25122)"`; -exports[`finance > 1337 > mask > with length, parenthesis, and ellipsis 1`] = `"(...25122)"`; +exports[`finance > 1337 > mask > with length and parenthesis option 1`] = `"...25122"`; + +exports[`finance > 1337 > mask > with length option 1`] = `"(...25122)"`; -exports[`finance > 1337 > mask > with parenthesis 1`] = `"(...2512)"`; +exports[`finance > 1337 > mask > with length, legacy parenthesis, and legacy ellipsis 1`] = `"(...25122)"`; + +exports[`finance > 1337 > mask > with length, parenthesis and ellipsis option 1`] = `"...25122"`; exports[`finance > 1337 > pin > noArgs 1`] = `"2512"`; exports[`finance > 1337 > pin > with length 1`] = `"2512254032"`; +exports[`finance > 1337 > pin > with length option 1`] = `"2512254032"`; + exports[`finance > 1337 > routingNumber 1`] = `"251225401"`; exports[`finance > 1337 > transactionDescription 1`] = `"withdrawal transaction at Cronin - Effertz using card ending with ***(...3927) for GTQ 262.02 in account ***54032552"`; diff --git a/test/finance.spec.ts b/test/finance.spec.ts index 7c90a62a..f5f640d7 100644 --- a/test/finance.spec.ts +++ b/test/finance.spec.ts @@ -29,19 +29,46 @@ describe('finance', () => { 'transactionDescription' ); - t.describeEach( - 'account', - 'pin' - )((t) => { - t.it('noArgs').it('with length', 10); + t.describe('account', (t) => { + t.it('noArgs') + .it('with length', 10) + .it('with length option', { length: 10 }); + }); + + t.describe('pin', (t) => { + t.it('noArgs') + .it('with length', 10) + .it('with length option', { length: 10 }); }); t.describe('amount', (t) => { t.it('noArgs') + .it('with min option', { min: 10 }) + .it('with min and max option', { min: 10, max: 50 }) + .it('with min, max and dec option', { min: 10, max: 50, dec: 5 }) + .it('with min, max, dec and symbol option', { + min: 10, + max: 50, + dec: 5, + symbol: '#', + }) + .it('with min, max, dec, symbol and autoFormat option', { + min: 10, + max: 50, + dec: 5, + symbol: '#', + autoFormat: false, + }) .it('with min', 10) - .it('with max', undefined, 50) - .it('with dec', undefined, undefined, 5) - .it('with min and max and dec and symbol', 10, 50, 5, '$'); + .it('with leagcy max', undefined, 50) + .it('with leagcy dec', undefined, undefined, 5) + .it( + 'with min, leagcy max, leagcy dec and leagcy symbol', + 10, + 50, + 5, + '$' + ); }); t.describe('bic', (t) => { @@ -50,20 +77,39 @@ describe('finance', () => { t.describe('iban', (t) => { t.it('noArgs') + .it('with formatted option', { formatted: true }) + .it('with formatted and countryCode option', { + formatted: true, + countryCode: 'DE', + }) .it('with formatted', true) .it('with formatted and countryCode', true, 'DE'); }); t.describe('creditCardNumber', (t) => { - t.it('noArgs').it('with issuer', 'visa'); + t.it('noArgs') + .it('with issuer', 'visa') + .it('with issuer option', { issuer: 'visa' }); }); t.describe('mask', (t) => { t.it('noArgs') .it('with length', 5) - .it('with parenthesis', undefined, true) - .it('with ellipsis', undefined, undefined, true) - .it('with length, parenthesis, and ellipsis', 5, true, true); + .it('with legacy parenthesis', undefined, true) + .it('with legacy ellipsis', undefined, undefined, true) + .it( + 'with length, legacy parenthesis, and legacy ellipsis', + 5, + true, + true + ) + .it('with length option', { length: 5 }) + .it('with length and parenthesis option', { length: 5, parens: false }) + .it('with length, parenthesis and ellipsis option', { + length: 5, + parens: false, + ellipsis: true, + }); }); }); @@ -121,7 +167,7 @@ describe('finance', () => { describe('mask()', () => { it('should set a default length', () => { const expected = 4; //default account mask length - const mask = faker.finance.mask(null, false, false); + const mask = faker.finance.mask(undefined, false, false); expect( mask, |
