diff --git a/src/definitions/finance.ts b/src/definitions/finance.ts index 52948aa2c15..8353cbfb126 100644 --- a/src/definitions/finance.ts +++ b/src/definitions/finance.ts @@ -17,6 +17,13 @@ export type FinanceDefinition = LocaleEntry<{ */ credit_card: { [issuer: string]: string[] }; + /** + * The first four digits of a US American Bankers Association (ABA) routing number. + * Digits 0-1 determine the federal district + * Digits 2-3 determine the city within that district + */ + federal_reserve_routing_symbol: string[]; + /** * Currencies including their name, code, symbol and ISO numeric code (e.g. `US Dollar` / `USD` / `$` / '840'). */ diff --git a/src/locales/base/finance/federal_reserve_routing_symbol.ts b/src/locales/base/finance/federal_reserve_routing_symbol.ts new file mode 100644 index 00000000000..2074de2683e --- /dev/null +++ b/src/locales/base/finance/federal_reserve_routing_symbol.ts @@ -0,0 +1,167 @@ +// Source: https://www.frbservices.org/resources/fees/check-key-to-routing-numbers.html +export default [ + '0110', + '0111', + '0112', + '0113', + '0114', + '0115', + '0116', + '0117', + '0118', + '0119', + '0210', + '0211', + '0212', + '0213', + '0214', + '0215', + '0216', + '0219', + '0220', + '0223', + '0260', + '0280', + '0310', + '0311', + '0312', + '0313', + '0319', + '0360', + '0410', + '0412', + '0420', + '0421', + '0422', + '0423', + '0430', + '0432', + '0433', + '0434', + '0440', + '0441', + '0442', + '0510', + '0514', + '0515', + '0519', + '0520', + '0521', + '0522', + '0530', + '0531', + '0532', + '0539', + '0540', + '0550', + '0560', + '0570', + '0610', + '0611', + '0612', + '0613', + '0620', + '0621', + '0622', + '0630', + '0631', + '0632', + '0640', + '0641', + '0642', + '0650', + '0651', + '0652', + '0653', + '0654', + '0655', + '0660', + '0670', + '0710', + '0711', + '0712', + '0719', + '0720', + '0724', + '0730', + '0739', + '0740', + '0749', + '0750', + '0759', + '0810', + '0812', + '0813', + '0815', + '0819', + '0820', + '0829', + '0830', + '0839', + '0840', + '0841', + '0842', + '0843', + '0863', + '0865', + '0910', + '0911', + '0912', + '0913', + '0914', + '0915', + '0918', + '0919', + '0920', + '0921', + '0929', + '0960', + '1010', + '1011', + '1012', + '1019', + '1020', + '1021', + '1022', + '1023', + '1030', + '1031', + '1039', + '1040', + '1041', + '1049', + '1070', + '1110', + '1111', + '1113', + '1119', + '1120', + '1122', + '1123', + '1130', + '1131', + '1140', + '1149', + '1163', + '1210', + '1211', + '1212', + '1213', + '1214', + '1220', + '1221', + '1222', + '1223', + '1224', + '1230', + '1231', + '1232', + '1233', + '1240', + '1241', + '1242', + '1243', + '1250', + '1251', + '1252', +]; diff --git a/src/locales/base/finance/index.ts b/src/locales/base/finance/index.ts new file mode 100644 index 00000000000..055ac36798a --- /dev/null +++ b/src/locales/base/finance/index.ts @@ -0,0 +1,12 @@ +/* + * This file is automatically generated. + * Run 'pnpm run generate:locales' to update. + */ +import type { FinanceDefinition } from '../../..'; +import federal_reserve_routing_symbol from './federal_reserve_routing_symbol'; + +const finance: FinanceDefinition = { + federal_reserve_routing_symbol, +}; + +export default finance; diff --git a/src/locales/base/index.ts b/src/locales/base/index.ts index 2e260172763..c76f4bd02bf 100644 --- a/src/locales/base/index.ts +++ b/src/locales/base/index.ts @@ -6,6 +6,7 @@ import type { LocaleDefinition } from '../..'; import color from './color'; import database from './database'; import date from './date'; +import finance from './finance'; import hacker from './hacker'; import internet from './internet'; import location from './location'; @@ -21,6 +22,7 @@ const base: LocaleDefinition = { color, database, date, + finance, hacker, internet, location, diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index 743d9acbcf3..5139b1f3124 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -180,19 +180,25 @@ export class FinanceModule extends ModuleBase { } /** - * Generates a random routing number. + * Generates a random [ABA routing number](https://en.wikipedia.org/wiki/ABA_routing_transit_number). * * @example - * faker.finance.routingNumber() // '522814402' + * faker.finance.routingNumber() // '062197511' * * @since 5.0.0 */ routingNumber(): string { - const routingNumber = this.faker.string.numeric({ - length: 8, + const federalReserveRoutingSymbol = this.faker.helpers.arrayElement( + this.faker.definitions.finance.federal_reserve_routing_symbol + ); + + const institutionIdentifier = this.faker.string.numeric({ + length: 4, allowLeadingZeros: true, }); + const routingNumber = federalReserveRoutingSymbol + institutionIdentifier; + // Modules 10 straight summation. let sum = 0; diff --git a/test/modules/__snapshots__/finance.spec.ts.snap b/test/modules/__snapshots__/finance.spec.ts.snap index e9187a192e5..b029fbd4425 100644 --- a/test/modules/__snapshots__/finance.spec.ts.snap +++ b/test/modules/__snapshots__/finance.spec.ts.snap @@ -75,7 +75,7 @@ exports[`finance > 42 > pin > with length 1`] = `"3975110867"`; exports[`finance > 42 > pin > with length option 1`] = `"3975110867"`; -exports[`finance > 42 > routingNumber 1`] = `"397511082"`; +exports[`finance > 42 > routingNumber 1`] = `"062197511"`; exports[`finance > 42 > transactionDescription 1`] = `"You made a withdrawal of SAR 598.66 at Streich - Aufderhar using card ending in ****9821 from account ***1354."`; @@ -156,7 +156,7 @@ exports[`finance > 1211 > pin > with length 1`] = `"9829667368"`; exports[`finance > 1211 > pin > with length option 1`] = `"9829667368"`; -exports[`finance > 1211 > routingNumber 1`] = `"982966738"`; +exports[`finance > 1211 > routingNumber 1`] = `"122482962"`; exports[`finance > 1211 > transactionDescription 1`] = `"withdrawal transaction at Paucek - Powlowski using card ending with ****8768 for KES 867.32 in account ***8251."`; @@ -237,7 +237,7 @@ exports[`finance > 1337 > pin > with length 1`] = `"2124352971"`; exports[`finance > 1337 > pin > with length option 1`] = `"2124352971"`; -exports[`finance > 1337 > routingNumber 1`] = `"212435298"`; +exports[`finance > 1337 > routingNumber 1`] = `"051412430"`; exports[`finance > 1337 > transactionDescription 1`] = `"Payment of CAD 278.12 for invoice at Wolf - Howe, processed with card ending ****6194 linked to account ***7734."`; diff --git a/test/modules/finance.spec.ts b/test/modules/finance.spec.ts index 0ef370d9569..292e1719114 100644 --- a/test/modules/finance.spec.ts +++ b/test/modules/finance.spec.ts @@ -1,3 +1,4 @@ +import { isAbaRouting } from 'validator'; import isCreditCard from 'validator/lib/isCreditCard'; import isLuhnNumber from 'validator/lib/isLuhnNumber'; import { describe, expect, it } from 'vitest'; @@ -139,10 +140,22 @@ describe('finance', () => { }); describe('routingNumber()', () => { - it('should return a string', () => { + it('should return a valid ABA routing number', () => { const routingNumber = faker.finance.routingNumber(); expect(routingNumber).toBeTypeOf('string'); + expect(routingNumber).toSatisfy(isAbaRouting); + }); + + it('should correspond to a valid federal reserve district', () => { + const routingNumber = faker.finance.routingNumber(); + + const firstTwoDigits = routingNumber.substring(0, 2); + const federalReserveDistrict = Number.parseInt(firstTwoDigits); + + expect(federalReserveDistrict).toBeTypeOf('number'); + expect(federalReserveDistrict).toBeGreaterThan(0); + expect(federalReserveDistrict).toBeLessThanOrEqual(12); }); });