diff --git a/src/finance.ts b/src/finance.ts new file mode 100644 index 00000000000..4ccc06bdd7b --- /dev/null +++ b/src/finance.ts @@ -0,0 +1,410 @@ +import type { Faker } from '.'; +import type { Helpers } from './helpers'; +import ibanLib from './iban'; + +export class Finance { + readonly ibanLib = ibanLib; + readonly Helpers: Helpers; + + constructor(private readonly faker: Faker) { + this.Helpers = this.faker.helpers; + + // Bind `this` so namespaced is working correctly + for (const name of Object.getOwnPropertyNames(Finance.prototype)) { + if (name === 'constructor' || typeof this[name] !== 'function') { + continue; + } + this[name] = this[name].bind(this); + } + } + + /** + * account + * + * @method faker.finance.account + * @param length + */ + account(length?: number) { + length ||= 8; + let template = ''; + + for (let i = 0; i < length; i++) { + template += '#'; + } + length = null; + return this.Helpers.replaceSymbolWithNumber(template); + } + + /** + * accountName + * + * @method faker.finance.accountName + */ + accountName(): string { + return [ + this.Helpers.randomize(this.faker.definitions.finance.account_type), + 'Account', + ].join(' '); + } + + /** + * routingNumber + * + * @method faker.finance.routingNumber + */ + routingNumber() { + const routingNumber = this.Helpers.replaceSymbolWithNumber('########'); + + // Modules 10 straight summation. + let sum = 0; + + for (let i = 0; i < routingNumber.length; i += 3) { + sum += Number(routingNumber[i]) * 3; + sum += Number(routingNumber[i + 1]) * 7; + sum += Number(routingNumber[i + 2]) || 0; + } + + return routingNumber + (Math.ceil(sum / 10) * 10 - sum); + } + + /** + * mask + * + * @method faker.finance.mask + * @param length + * @param parens + * @param ellipsis + */ + mask(length?: number, parens?: boolean, ellipsis?: boolean): string { + // set defaults + length = + length == 0 || !length || typeof length == 'undefined' ? 4 : length; + parens = parens == null ? true : parens; + ellipsis = ellipsis == null ? true : ellipsis; + + // create a template for length + let template = ''; + + for (let i = 0; i < length; i++) { + template = template + '#'; + } + + //prefix with ellipsis + template = ellipsis ? ['...', template].join('') : template; + + template = parens ? ['(', template, ')'].join('') : template; + + //generate random numbers + template = this.Helpers.replaceSymbolWithNumber(template); + + return template; + } + + // min and max take in minimum and maximum amounts, dec is the decimal place you want rounded to, symbol is $, €, £, etc + // NOTE: this returns a string representation of the value, if you want a number use parseFloat and no symbol + + /** + * amount + * + * @method faker.finance.amount + * @param min + * @param max + * @param dec + * @param symbol + */ + amount( + min: number = 0, + max: number = 1000, + dec: number = 2, + symbol: string = '', + autoFormat?: boolean + ): string { + const randValue = this.faker.datatype.number({ + max, + min, + precision: Math.pow(10, -dec), + }); + + let formattedString: string; + if (autoFormat) { + formattedString = randValue.toLocaleString(undefined, { + minimumFractionDigits: dec, + }); + } else { + formattedString = randValue.toFixed(dec); + } + + return symbol + formattedString; + } + + /** + * transactionType + * + * @method faker.finance.transactionType + */ + transactionType() { + return this.Helpers.randomize( + this.faker.definitions.finance.transaction_type + ); + } + + /** + * currencyCode + * + * @method faker.finance.currencyCode + */ + currencyCode() { + // TODO @Shinigami92 2022-01-14: missing second parameter + // @ts-expect-error + return this.faker.random.objectElement( + this.faker.definitions.finance.currency + )['code']; + } + + /** + * currencyName + * + * @method faker.finance.currencyName + */ + currencyName() { + return this.faker.random.objectElement( + this.faker.definitions.finance.currency, + 'key' + ); + } + + /** + * currencySymbol + * + * @method faker.finance.currencySymbol + */ + currencySymbol() { + let symbol; + + while (!symbol) { + symbol = + // TODO @Shinigami92 2022-01-14: missing second parameter + // @ts-expect-error + this.faker.random.objectElement( + this.faker.definitions.finance.currency + )['symbol']; + } + return symbol; + } + + /** + * bitcoinAddress + * + * @method faker.finance.bitcoinAddress + */ + bitcoinAddress(): string { + const addressLength = this.faker.datatype.number({ min: 25, max: 34 }); + + let address = this.faker.random.arrayElement(['1', '3']); + + for (let i = 0; i < addressLength - 1; i++) + address += this.faker.random.arrayElement( + '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'.split('') + ); + + return address; + } + + /** + * litecoinAddress + * + * @method faker.finance.litecoinAddress + */ + litecoinAddress(): string { + const addressLength = this.faker.datatype.number({ min: 26, max: 33 }); + + let address = this.faker.random.arrayElement(['L', 'M', '3']); + + for (let i = 0; i < addressLength - 1; i++) + address += this.faker.random.arrayElement( + '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'.split('') + ); + + return address; + } + + /** + * Credit card number + * + * @method faker.finance.creditCardNumber + * @param provider scheme + */ + creditCardNumber(provider = '') { + let format: string; + let formats: string | string[]; + const localeFormat = this.faker.definitions.finance.credit_card; + if (provider in localeFormat) { + formats = localeFormat[provider]; // there could be multiple formats + if (typeof formats === 'string') { + format = formats; + } else { + format = this.faker.random.arrayElement(formats); + } + } else if (provider.match(/#/)) { + // The user chose an optional scheme + format = provider; + } else { + // Choose a random provider + if (typeof localeFormat === 'string') { + format = localeFormat; + } else if (typeof localeFormat === 'object') { + // Credit cards are in a object structure + formats = this.faker.random.objectElement(localeFormat, 'value'); // There could be multiple formats + if (typeof formats === 'string') { + format = formats; + } else { + format = this.faker.random.arrayElement(formats); + } + } + } + format = format.replace(/\//g, ''); + return this.Helpers.replaceCreditCardSymbols(format); + } + + /** + * Credit card CVV + * + * @method faker.finance.creditCardCVV + */ + creditCardCVV(): string { + let cvv = ''; + for (let i = 0; i < 3; i++) { + cvv += this.faker.datatype.number({ max: 9 }).toString(); + } + return cvv; + } + + /** + * ethereumAddress + * + * @method faker.finance.ethereumAddress + */ + ethereumAddress(): string { + const address = this.faker.datatype.hexaDecimal(40).toLowerCase(); + return address; + } + + /** + * iban + * + * @param formatted Return a formatted version of the generated IBAN. + * @param 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. + * + * @method faker.finance.iban + */ + iban(formatted: boolean = false, countryCode: string): string { + let ibanFormat; + if (countryCode) { + const findFormat = (currentFormat) => + currentFormat.country === countryCode; + ibanFormat = this.ibanLib.formats.find(findFormat); + } else { + ibanFormat = this.faker.random.arrayElement(this.ibanLib.formats); + } + + if (!ibanFormat) { + throw new Error('Country code ' + countryCode + ' not supported.'); + } + + let s = ''; + let count = 0; + for (let b = 0; b < ibanFormat.bban.length; b++) { + const bban = ibanFormat.bban[b]; + let c = bban.count; + count += bban.count; + while (c > 0) { + if (bban.type == 'a') { + s += this.faker.random.arrayElement(this.ibanLib.alpha); + } else if (bban.type == 'c') { + if (this.faker.datatype.number(100) < 80) { + s += this.faker.datatype.number(9); + } else { + s += this.faker.random.arrayElement(this.ibanLib.alpha); + } + } else { + if (c >= 3 && this.faker.datatype.number(100) < 30) { + if (this.faker.datatype.boolean()) { + s += this.faker.random.arrayElement(this.ibanLib.pattern100); + c -= 2; + } else { + s += this.faker.random.arrayElement(this.ibanLib.pattern10); + c--; + } + } else { + s += this.faker.datatype.number(9); + } + } + c--; + } + s = s.substring(0, count); + } + let checksum: string | number = + 98 - + this.ibanLib.mod97( + this.ibanLib.toDigitString(s + ibanFormat.country + '00') + ); + if (checksum < 10) { + checksum = '0' + checksum; + } + const iban = ibanFormat.country + checksum + s; + return formatted ? iban.match(/.{1,4}/g).join(' ') : iban; + } + + /** + * bic + * + * @method faker.finance.bic + */ + bic(): string { + const vowels = ['A', 'E', 'I', 'O', 'U']; + const prob = this.faker.datatype.number(100); + return ( + this.Helpers.replaceSymbols('???') + + this.faker.random.arrayElement(vowels) + + this.faker.random.arrayElement(this.ibanLib.iso3166) + + this.Helpers.replaceSymbols('?') + + '1' + + (prob < 10 + ? this.Helpers.replaceSymbols( + '?' + this.faker.random.arrayElement(vowels) + '?' + ) + : prob < 40 + ? this.Helpers.replaceSymbols('###') + : '') + ); + } + + /** + * description + * + * @method faker.finance.transactionDescription + */ + transactionDescription(): string { + const transaction = this.Helpers.createTransaction(); + const account = transaction.account; + const amount = transaction.amount; + const transactionType = transaction.type; + const company = transaction.business; + const card = this.faker.finance.mask(); + const currency = this.faker.finance.currencyCode(); + return ( + transactionType + + ' transaction at ' + + company + + ' using card ending with ***' + + card + + ' for ' + + currency + + ' ' + + amount + + ' in account ***' + + account + ); + } +} diff --git a/src/iban.ts b/src/iban.ts new file mode 100644 index 00000000000..8b3c9fb9939 --- /dev/null +++ b/src/iban.ts @@ -0,0 +1,1414 @@ +export default { + alpha: [ + 'A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G', + 'H', + 'I', + 'J', + 'K', + 'L', + 'M', + 'N', + 'O', + 'P', + 'Q', + 'R', + 'S', + 'T', + 'U', + 'V', + 'W', + 'X', + 'Y', + 'Z', + ], + pattern10: ['01', '02', '03', '04', '05', '06', '07', '08', '09'], + pattern100: ['001', '002', '003', '004', '005', '006', '007', '008', '009'], + toDigitString: (str: string): string => + str.replace( + /[A-Z]/gi, + (match) => + // TODO @Shinigami92 2022-01-13: This needs to be converted to string + // @ts-expect-error + match.toUpperCase().charCodeAt(0) - 55 + ), + mod97: (digitStr): number => { + let m = 0; + for (let i = 0; i < digitStr.length; i++) { + m = (m * 10 + (digitStr[i] | 0)) % 97; + } + return m; + }, + formats: [ + { + country: 'AL', + total: 28, + bban: [ + { + type: 'n', + count: 8, + }, + { + type: 'c', + count: 16, + }, + ], + format: 'ALkk bbbs sssx cccc cccc cccc cccc', + }, + { + country: 'AD', + total: 24, + bban: [ + { + type: 'n', + count: 8, + }, + { + type: 'c', + count: 12, + }, + ], + format: 'ADkk bbbb ssss cccc cccc cccc', + }, + { + country: 'AT', + total: 20, + bban: [ + { + type: 'n', + count: 5, + }, + { + type: 'n', + count: 11, + }, + ], + format: 'ATkk bbbb bccc cccc cccc', + }, + { + // Azerbaijan + // https://transferwise.com/fr/iban/azerbaijan + // Length 28 + // BBAN 2c,16n + // GEkk bbbb cccc cccc cccc cccc cccc + // b = National bank code (alpha) + // c = Account number + // example IBAN AZ21 NABZ 0000 0000 1370 1000 1944 + country: 'AZ', + total: 28, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'n', + count: 20, + }, + ], + format: 'AZkk bbbb cccc cccc cccc cccc cccc', + }, + { + country: 'BH', + total: 22, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'c', + count: 14, + }, + ], + format: 'BHkk bbbb cccc cccc cccc cc', + }, + { + country: 'BE', + total: 16, + bban: [ + { + type: 'n', + count: 3, + }, + { + type: 'n', + count: 9, + }, + ], + format: 'BEkk bbbc cccc ccxx', + }, + { + country: 'BA', + total: 20, + bban: [ + { + type: 'n', + count: 6, + }, + { + type: 'n', + count: 10, + }, + ], + format: 'BAkk bbbs sscc cccc ccxx', + }, + { + country: 'BR', + total: 29, + bban: [ + { + type: 'n', + count: 13, + }, + { + type: 'n', + count: 10, + }, + { + type: 'a', + count: 1, + }, + { + type: 'c', + count: 1, + }, + ], + format: 'BRkk bbbb bbbb ssss sccc cccc ccct n', + }, + { + country: 'BG', + total: 22, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'n', + count: 6, + }, + { + type: 'c', + count: 8, + }, + ], + format: 'BGkk bbbb ssss ddcc cccc cc', + }, + { + country: 'CR', + total: 21, + bban: [ + { + type: 'n', + count: 3, + }, + { + type: 'n', + count: 14, + }, + ], + format: 'CRkk bbbc cccc cccc cccc c', + }, + { + country: 'HR', + total: 21, + bban: [ + { + type: 'n', + count: 7, + }, + { + type: 'n', + count: 10, + }, + ], + format: 'HRkk bbbb bbbc cccc cccc c', + }, + { + country: 'CY', + total: 28, + bban: [ + { + type: 'n', + count: 8, + }, + { + type: 'c', + count: 16, + }, + ], + format: 'CYkk bbbs ssss cccc cccc cccc cccc', + }, + { + country: 'CZ', + total: 24, + bban: [ + { + type: 'n', + count: 10, + }, + { + type: 'n', + count: 10, + }, + ], + format: 'CZkk bbbb ssss sscc cccc cccc', + }, + { + country: 'DK', + total: 18, + bban: [ + { + type: 'n', + count: 4, + }, + { + type: 'n', + count: 10, + }, + ], + format: 'DKkk bbbb cccc cccc cc', + }, + { + country: 'DO', + total: 28, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'n', + count: 20, + }, + ], + format: 'DOkk bbbb cccc cccc cccc cccc cccc', + }, + { + country: 'TL', + total: 23, + bban: [ + { + type: 'n', + count: 3, + }, + { + type: 'n', + count: 16, + }, + ], + format: 'TLkk bbbc cccc cccc cccc cxx', + }, + { + country: 'EE', + total: 20, + bban: [ + { + type: 'n', + count: 4, + }, + { + type: 'n', + count: 12, + }, + ], + format: 'EEkk bbss cccc cccc cccx', + }, + { + country: 'FO', + total: 18, + bban: [ + { + type: 'n', + count: 4, + }, + { + type: 'n', + count: 10, + }, + ], + format: 'FOkk bbbb cccc cccc cx', + }, + { + country: 'FI', + total: 18, + bban: [ + { + type: 'n', + count: 6, + }, + { + type: 'n', + count: 8, + }, + ], + format: 'FIkk bbbb bbcc cccc cx', + }, + { + country: 'FR', + total: 27, + bban: [ + { + type: 'n', + count: 10, + }, + { + type: 'c', + count: 11, + }, + { + type: 'n', + count: 2, + }, + ], + format: 'FRkk bbbb bggg ggcc cccc cccc cxx', + }, + { + country: 'GE', + total: 22, + bban: [ + { + type: 'a', + count: 2, + }, + { + type: 'n', + count: 16, + }, + ], + format: 'GEkk bbcc cccc cccc cccc cc', + }, + { + country: 'DE', + total: 22, + bban: [ + { + type: 'n', + count: 8, + }, + { + type: 'n', + count: 10, + }, + ], + format: 'DEkk bbbb bbbb cccc cccc cc', + }, + { + country: 'GI', + total: 23, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'c', + count: 15, + }, + ], + format: 'GIkk bbbb cccc cccc cccc ccc', + }, + { + country: 'GR', + total: 27, + bban: [ + { + type: 'n', + count: 7, + }, + { + type: 'c', + count: 16, + }, + ], + format: 'GRkk bbbs sssc cccc cccc cccc ccc', + }, + { + country: 'GL', + total: 18, + bban: [ + { + type: 'n', + count: 4, + }, + { + type: 'n', + count: 10, + }, + ], + format: 'GLkk bbbb cccc cccc cc', + }, + { + country: 'GT', + total: 28, + bban: [ + { + type: 'c', + count: 4, + }, + { + type: 'c', + count: 4, + }, + { + type: 'c', + count: 16, + }, + ], + format: 'GTkk bbbb mmtt cccc cccc cccc cccc', + }, + { + country: 'HU', + total: 28, + bban: [ + { + type: 'n', + count: 8, + }, + { + type: 'n', + count: 16, + }, + ], + format: 'HUkk bbbs sssk cccc cccc cccc cccx', + }, + { + country: 'IS', + total: 26, + bban: [ + { + type: 'n', + count: 6, + }, + { + type: 'n', + count: 16, + }, + ], + format: 'ISkk bbbb sscc cccc iiii iiii ii', + }, + { + country: 'IE', + total: 22, + bban: [ + { + type: 'c', + count: 4, + }, + { + type: 'n', + count: 6, + }, + { + type: 'n', + count: 8, + }, + ], + format: 'IEkk aaaa bbbb bbcc cccc cc', + }, + { + country: 'IL', + total: 23, + bban: [ + { + type: 'n', + count: 6, + }, + { + type: 'n', + count: 13, + }, + ], + format: 'ILkk bbbn nncc cccc cccc ccc', + }, + { + country: 'IT', + total: 27, + bban: [ + { + type: 'a', + count: 1, + }, + { + type: 'n', + count: 10, + }, + { + type: 'c', + count: 12, + }, + ], + format: 'ITkk xaaa aabb bbbc cccc cccc ccc', + }, + { + country: 'JO', + total: 30, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'n', + count: 4, + }, + { + type: 'n', + count: 18, + }, + ], + format: 'JOkk bbbb nnnn cccc cccc cccc cccc cc', + }, + { + country: 'KZ', + total: 20, + bban: [ + { + type: 'n', + count: 3, + }, + { + type: 'c', + count: 13, + }, + ], + format: 'KZkk bbbc cccc cccc cccc', + }, + { + country: 'XK', + total: 20, + bban: [ + { + type: 'n', + count: 4, + }, + { + type: 'n', + count: 12, + }, + ], + format: 'XKkk bbbb cccc cccc cccc', + }, + { + country: 'KW', + total: 30, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'c', + count: 22, + }, + ], + format: 'KWkk bbbb cccc cccc cccc cccc cccc cc', + }, + { + country: 'LV', + total: 21, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'c', + count: 13, + }, + ], + format: 'LVkk bbbb cccc cccc cccc c', + }, + { + country: 'LB', + total: 28, + bban: [ + { + type: 'n', + count: 4, + }, + { + type: 'c', + count: 20, + }, + ], + format: 'LBkk bbbb cccc cccc cccc cccc cccc', + }, + { + country: 'LI', + total: 21, + bban: [ + { + type: 'n', + count: 5, + }, + { + type: 'c', + count: 12, + }, + ], + format: 'LIkk bbbb bccc cccc cccc c', + }, + { + country: 'LT', + total: 20, + bban: [ + { + type: 'n', + count: 5, + }, + { + type: 'n', + count: 11, + }, + ], + format: 'LTkk bbbb bccc cccc cccc', + }, + { + country: 'LU', + total: 20, + bban: [ + { + type: 'n', + count: 3, + }, + { + type: 'c', + count: 13, + }, + ], + format: 'LUkk bbbc cccc cccc cccc', + }, + { + country: 'MK', + total: 19, + bban: [ + { + type: 'n', + count: 3, + }, + { + type: 'c', + count: 10, + }, + { + type: 'n', + count: 2, + }, + ], + format: 'MKkk bbbc cccc cccc cxx', + }, + { + country: 'MT', + total: 31, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'n', + count: 5, + }, + { + type: 'c', + count: 18, + }, + ], + format: 'MTkk bbbb ssss sccc cccc cccc cccc ccc', + }, + { + country: 'MR', + total: 27, + bban: [ + { + type: 'n', + count: 10, + }, + { + type: 'n', + count: 13, + }, + ], + format: 'MRkk bbbb bsss sscc cccc cccc cxx', + }, + { + country: 'MU', + total: 30, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'n', + count: 4, + }, + { + type: 'n', + count: 15, + }, + { + type: 'a', + count: 3, + }, + ], + format: 'MUkk bbbb bbss cccc cccc cccc 000d dd', + }, + { + country: 'MC', + total: 27, + bban: [ + { + type: 'n', + count: 10, + }, + { + type: 'c', + count: 11, + }, + { + type: 'n', + count: 2, + }, + ], + format: 'MCkk bbbb bsss sscc cccc cccc cxx', + }, + { + country: 'MD', + total: 24, + bban: [ + { + type: 'c', + count: 2, + }, + { + type: 'c', + count: 18, + }, + ], + format: 'MDkk bbcc cccc cccc cccc cccc', + }, + { + country: 'ME', + total: 22, + bban: [ + { + type: 'n', + count: 3, + }, + { + type: 'n', + count: 15, + }, + ], + format: 'MEkk bbbc cccc cccc cccc xx', + }, + { + country: 'NL', + total: 18, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'n', + count: 10, + }, + ], + format: 'NLkk bbbb cccc cccc cc', + }, + { + country: 'NO', + total: 15, + bban: [ + { + type: 'n', + count: 4, + }, + { + type: 'n', + count: 7, + }, + ], + format: 'NOkk bbbb cccc ccx', + }, + { + country: 'PK', + total: 24, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'n', + count: 16, + }, + ], + format: 'PKkk bbbb cccc cccc cccc cccc', + }, + { + country: 'PS', + total: 29, + bban: [ + { + type: 'c', + count: 4, + }, + { + type: 'n', + count: 9, + }, + { + type: 'n', + count: 12, + }, + ], + format: 'PSkk bbbb xxxx xxxx xccc cccc cccc c', + }, + { + country: 'PL', + total: 28, + bban: [ + { + type: 'n', + count: 8, + }, + { + type: 'n', + count: 16, + }, + ], + format: 'PLkk bbbs sssx cccc cccc cccc cccc', + }, + { + country: 'PT', + total: 25, + bban: [ + { + type: 'n', + count: 8, + }, + { + type: 'n', + count: 13, + }, + ], + format: 'PTkk bbbb ssss cccc cccc cccx x', + }, + { + country: 'QA', + total: 29, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'c', + count: 21, + }, + ], + format: 'QAkk bbbb cccc cccc cccc cccc cccc c', + }, + { + country: 'RO', + total: 24, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'c', + count: 16, + }, + ], + format: 'ROkk bbbb cccc cccc cccc cccc', + }, + { + country: 'SM', + total: 27, + bban: [ + { + type: 'a', + count: 1, + }, + { + type: 'n', + count: 10, + }, + { + type: 'c', + count: 12, + }, + ], + format: 'SMkk xaaa aabb bbbc cccc cccc ccc', + }, + { + country: 'SA', + total: 24, + bban: [ + { + type: 'n', + count: 2, + }, + { + type: 'c', + count: 18, + }, + ], + format: 'SAkk bbcc cccc cccc cccc cccc', + }, + { + country: 'RS', + total: 22, + bban: [ + { + type: 'n', + count: 3, + }, + { + type: 'n', + count: 15, + }, + ], + format: 'RSkk bbbc cccc cccc cccc xx', + }, + { + country: 'SK', + total: 24, + bban: [ + { + type: 'n', + count: 10, + }, + { + type: 'n', + count: 10, + }, + ], + format: 'SKkk bbbb ssss sscc cccc cccc', + }, + { + country: 'SI', + total: 19, + bban: [ + { + type: 'n', + count: 5, + }, + { + type: 'n', + count: 10, + }, + ], + format: 'SIkk bbss sccc cccc cxx', + }, + { + country: 'ES', + total: 24, + bban: [ + { + type: 'n', + count: 10, + }, + { + type: 'n', + count: 10, + }, + ], + format: 'ESkk bbbb gggg xxcc cccc cccc', + }, + { + country: 'SE', + total: 24, + bban: [ + { + type: 'n', + count: 3, + }, + { + type: 'n', + count: 17, + }, + ], + format: 'SEkk bbbc cccc cccc cccc cccc', + }, + { + country: 'CH', + total: 21, + bban: [ + { + type: 'n', + count: 5, + }, + { + type: 'c', + count: 12, + }, + ], + format: 'CHkk bbbb bccc cccc cccc c', + }, + { + country: 'TN', + total: 24, + bban: [ + { + type: 'n', + count: 5, + }, + { + type: 'n', + count: 15, + }, + ], + format: 'TNkk bbss sccc cccc cccc cccc', + }, + { + country: 'TR', + total: 26, + bban: [ + { + type: 'n', + count: 5, + }, + { + type: 'n', + count: 1, + }, + { + type: 'n', + count: 16, + }, + ], + format: 'TRkk bbbb bxcc cccc cccc cccc cc', + }, + { + country: 'AE', + total: 23, + bban: [ + { + type: 'n', + count: 3, + }, + { + type: 'n', + count: 16, + }, + ], + format: 'AEkk bbbc cccc cccc cccc ccc', + }, + { + country: 'GB', + total: 22, + bban: [ + { + type: 'a', + count: 4, + }, + { + type: 'n', + count: 6, + }, + { + type: 'n', + count: 8, + }, + ], + format: 'GBkk bbbb ssss sscc cccc cc', + }, + { + country: 'VG', + total: 24, + bban: [ + { + type: 'c', + count: 4, + }, + { + type: 'n', + count: 16, + }, + ], + format: 'VGkk bbbb cccc cccc cccc cccc', + }, + ], + iso3166: [ + 'AC', + 'AD', + 'AE', + 'AF', + 'AG', + 'AI', + 'AL', + 'AM', + 'AN', + 'AO', + 'AQ', + 'AR', + 'AS', + 'AT', + 'AU', + 'AW', + 'AX', + 'AZ', + 'BA', + 'BB', + 'BD', + 'BE', + 'BF', + 'BG', + 'BH', + 'BI', + 'BJ', + 'BL', + 'BM', + 'BN', + 'BO', + 'BQ', + 'BR', + 'BS', + 'BT', + 'BU', + 'BV', + 'BW', + 'BY', + 'BZ', + 'CA', + 'CC', + 'CD', + 'CE', + 'CF', + 'CG', + 'CH', + 'CI', + 'CK', + 'CL', + 'CM', + 'CN', + 'CO', + 'CP', + 'CR', + 'CS', + 'CS', + 'CU', + 'CV', + 'CW', + 'CX', + 'CY', + 'CZ', + 'DD', + 'DE', + 'DG', + 'DJ', + 'DK', + 'DM', + 'DO', + 'DZ', + 'EA', + 'EC', + 'EE', + 'EG', + 'EH', + 'ER', + 'ES', + 'ET', + 'EU', + 'FI', + 'FJ', + 'FK', + 'FM', + 'FO', + 'FR', + 'FX', + 'GA', + 'GB', + 'GD', + 'GE', + 'GF', + 'GG', + 'GH', + 'GI', + 'GL', + 'GM', + 'GN', + 'GP', + 'GQ', + 'GR', + 'GS', + 'GT', + 'GU', + 'GW', + 'GY', + 'HK', + 'HM', + 'HN', + 'HR', + 'HT', + 'HU', + 'IC', + 'ID', + 'IE', + 'IL', + 'IM', + 'IN', + 'IO', + 'IQ', + 'IR', + 'IS', + 'IT', + 'JE', + 'JM', + 'JO', + 'JP', + 'KE', + 'KG', + 'KH', + 'KI', + 'KM', + 'KN', + 'KP', + 'KR', + 'KW', + 'KY', + 'KZ', + 'LA', + 'LB', + 'LC', + 'LI', + 'LK', + 'LR', + 'LS', + 'LT', + 'LU', + 'LV', + 'LY', + 'MA', + 'MC', + 'MD', + 'ME', + 'MF', + 'MG', + 'MH', + 'MK', + 'ML', + 'MM', + 'MN', + 'MO', + 'MP', + 'MQ', + 'MR', + 'MS', + 'MT', + 'MU', + 'MV', + 'MW', + 'MX', + 'MY', + 'MZ', + 'NA', + 'NC', + 'NE', + 'NF', + 'NG', + 'NI', + 'NL', + 'NO', + 'NP', + 'NR', + 'NT', + 'NU', + 'NZ', + 'OM', + 'PA', + 'PE', + 'PF', + 'PG', + 'PH', + 'PK', + 'PL', + 'PM', + 'PN', + 'PR', + 'PS', + 'PT', + 'PW', + 'PY', + 'QA', + 'RE', + 'RO', + 'RS', + 'RU', + 'RW', + 'SA', + 'SB', + 'SC', + 'SD', + 'SE', + 'SG', + 'SH', + 'SI', + 'SJ', + 'SK', + 'SL', + 'SM', + 'SN', + 'SO', + 'SR', + 'SS', + 'ST', + 'SU', + 'SV', + 'SX', + 'SY', + 'SZ', + 'TA', + 'TC', + 'TD', + 'TF', + 'TG', + 'TH', + 'TJ', + 'TK', + 'TL', + 'TM', + 'TN', + 'TO', + 'TR', + 'TT', + 'TV', + 'TW', + 'TZ', + 'UA', + 'UG', + 'UM', + 'US', + 'UY', + 'UZ', + 'VA', + 'VC', + 'VE', + 'VG', + 'VI', + 'VN', + 'VU', + 'WF', + 'WS', + 'YE', + 'YT', + 'YU', + 'ZA', + 'ZM', + 'ZR', + 'ZW', + ], +}; diff --git a/src/index.ts b/src/index.ts index cf2c81fc0cb..65dc62257b9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import { Database } from './database'; import { Datatype } from './datatype'; import { _Date } from './date'; import { Fake } from './fake'; +import { Finance } from './finance'; import { Git } from './git'; import { Hacker } from './hacker'; import { Helpers } from './helpers'; @@ -185,7 +186,7 @@ export class Faker { readonly company = new (require('./company'))(this); readonly database: Database = new Database(this); readonly date: _Date = new _Date(this); - readonly finance = new (require('./finance'))(this); + readonly finance = new Finance(this); readonly git: Git = new Git(this); readonly hacker: Hacker = new Hacker(this); // TODO @Shinigami92 2022-01-12: iban was not used diff --git a/test/finance.unit.js b/test/finance.unit.js index aeecba660b6..f1ae94a2041 100644 --- a/test/finance.unit.js +++ b/test/finance.unit.js @@ -415,7 +415,7 @@ describe('finance.js', function () { }); describe('iban()', function () { - var ibanLib = require('../lib/iban'); + var ibanLib = require('../lib/iban').default; it('returns a random yet formally correct IBAN number', function () { var iban = faker.finance.iban(); var bban = iban.substring(4) + iban.substring(0, 4); @@ -446,7 +446,7 @@ describe('finance.js', function () { }); describe('bic()', function () { - var ibanLib = require('../lib/iban'); + var ibanLib = require('../lib/iban').default; it('returns a random yet formally correct BIC number', function () { var bic = faker.finance.bic(); var expr = new RegExp( diff --git a/test/finance_iban.unit.js b/test/finance_iban.unit.js index e9298399c21..76979d52d23 100644 --- a/test/finance_iban.unit.js +++ b/test/finance_iban.unit.js @@ -39,7 +39,7 @@ describe('finance_iban.js', function () { // example IBAN GE29 NB00 0000 0101 9049 17 - var ibanLib = require('../lib/iban'); + var ibanLib = require('../lib/iban').default; it('IBAN for Georgia is correct', function () { faker.seed(17); @@ -99,7 +99,7 @@ describe('finance_iban.js', function () { // Account Code 16 digits // Total Length 24 chars - var ibanLib = require('../lib/iban'); + var ibanLib = require('../lib/iban').default; it('IBAN for Pakistan is correct', function () { faker.seed(28); @@ -165,7 +165,7 @@ describe('finance_iban.js', function () { // Chiffre d'indicatif national 0 // Numéro de compte bancaire 0519786457841326 - var ibanLib = require('../lib/iban'); + var ibanLib = require('../lib/iban').default; it('IBAN for Turkish is correct', function () { faker.seed(37); @@ -240,7 +240,7 @@ describe('finance_iban.js', function () { // example IBAN AZ21 NABZ 0000 0000 1370 1000 1944 - var ibanLib = require('../lib/iban'); + var ibanLib = require('../lib/iban').default; it('IBAN for Azerbaijan is correct', function () { faker.seed(21);