Skip to content

Commit c53c1fe

Browse files
woldakerwoldakerST-DDT
authored
fix(finance): routingNumber now uses real FederalReserveRoutingSymbol from lookup table. (#3429)
Co-authored-by: woldaker <woldaker@onphase.com> Co-authored-by: ST-DDT <ST-DDT@gmx.de>
1 parent 6153eb7 commit c53c1fe

7 files changed

Lines changed: 215 additions & 8 deletions

File tree

src/definitions/finance.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export type FinanceDefinition = LocaleEntry<{
1717
*/
1818
credit_card: { [issuer: string]: string[] };
1919

20+
/**
21+
* The first four digits of a US American Bankers Association (ABA) routing number.
22+
* Digits 0-1 determine the federal district
23+
* Digits 2-3 determine the city within that district
24+
*/
25+
federal_reserve_routing_symbol: string[];
26+
2027
/**
2128
* Currencies including their name, code, symbol and ISO numeric code (e.g. `US Dollar` / `USD` / `$` / '840').
2229
*/
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// Source: https://www.frbservices.org/resources/fees/check-key-to-routing-numbers.html
2+
export default [
3+
'0110',
4+
'0111',
5+
'0112',
6+
'0113',
7+
'0114',
8+
'0115',
9+
'0116',
10+
'0117',
11+
'0118',
12+
'0119',
13+
'0210',
14+
'0211',
15+
'0212',
16+
'0213',
17+
'0214',
18+
'0215',
19+
'0216',
20+
'0219',
21+
'0220',
22+
'0223',
23+
'0260',
24+
'0280',
25+
'0310',
26+
'0311',
27+
'0312',
28+
'0313',
29+
'0319',
30+
'0360',
31+
'0410',
32+
'0412',
33+
'0420',
34+
'0421',
35+
'0422',
36+
'0423',
37+
'0430',
38+
'0432',
39+
'0433',
40+
'0434',
41+
'0440',
42+
'0441',
43+
'0442',
44+
'0510',
45+
'0514',
46+
'0515',
47+
'0519',
48+
'0520',
49+
'0521',
50+
'0522',
51+
'0530',
52+
'0531',
53+
'0532',
54+
'0539',
55+
'0540',
56+
'0550',
57+
'0560',
58+
'0570',
59+
'0610',
60+
'0611',
61+
'0612',
62+
'0613',
63+
'0620',
64+
'0621',
65+
'0622',
66+
'0630',
67+
'0631',
68+
'0632',
69+
'0640',
70+
'0641',
71+
'0642',
72+
'0650',
73+
'0651',
74+
'0652',
75+
'0653',
76+
'0654',
77+
'0655',
78+
'0660',
79+
'0670',
80+
'0710',
81+
'0711',
82+
'0712',
83+
'0719',
84+
'0720',
85+
'0724',
86+
'0730',
87+
'0739',
88+
'0740',
89+
'0749',
90+
'0750',
91+
'0759',
92+
'0810',
93+
'0812',
94+
'0813',
95+
'0815',
96+
'0819',
97+
'0820',
98+
'0829',
99+
'0830',
100+
'0839',
101+
'0840',
102+
'0841',
103+
'0842',
104+
'0843',
105+
'0863',
106+
'0865',
107+
'0910',
108+
'0911',
109+
'0912',
110+
'0913',
111+
'0914',
112+
'0915',
113+
'0918',
114+
'0919',
115+
'0920',
116+
'0921',
117+
'0929',
118+
'0960',
119+
'1010',
120+
'1011',
121+
'1012',
122+
'1019',
123+
'1020',
124+
'1021',
125+
'1022',
126+
'1023',
127+
'1030',
128+
'1031',
129+
'1039',
130+
'1040',
131+
'1041',
132+
'1049',
133+
'1070',
134+
'1110',
135+
'1111',
136+
'1113',
137+
'1119',
138+
'1120',
139+
'1122',
140+
'1123',
141+
'1130',
142+
'1131',
143+
'1140',
144+
'1149',
145+
'1163',
146+
'1210',
147+
'1211',
148+
'1212',
149+
'1213',
150+
'1214',
151+
'1220',
152+
'1221',
153+
'1222',
154+
'1223',
155+
'1224',
156+
'1230',
157+
'1231',
158+
'1232',
159+
'1233',
160+
'1240',
161+
'1241',
162+
'1242',
163+
'1243',
164+
'1250',
165+
'1251',
166+
'1252',
167+
];

src/locales/base/finance/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* This file is automatically generated.
3+
* Run 'pnpm run generate:locales' to update.
4+
*/
5+
import type { FinanceDefinition } from '../../..';
6+
import federal_reserve_routing_symbol from './federal_reserve_routing_symbol';
7+
8+
const finance: FinanceDefinition = {
9+
federal_reserve_routing_symbol,
10+
};
11+
12+
export default finance;

src/locales/base/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { LocaleDefinition } from '../..';
66
import color from './color';
77
import database from './database';
88
import date from './date';
9+
import finance from './finance';
910
import hacker from './hacker';
1011
import internet from './internet';
1112
import location from './location';
@@ -21,6 +22,7 @@ const base: LocaleDefinition = {
2122
color,
2223
database,
2324
date,
25+
finance,
2426
hacker,
2527
internet,
2628
location,

src/modules/finance/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,25 @@ export class FinanceModule extends ModuleBase {
180180
}
181181

182182
/**
183-
* Generates a random routing number.
183+
* Generates a random [ABA routing number](https://en.wikipedia.org/wiki/ABA_routing_transit_number).
184184
*
185185
* @example
186-
* faker.finance.routingNumber() // '522814402'
186+
* faker.finance.routingNumber() // '062197511'
187187
*
188188
* @since 5.0.0
189189
*/
190190
routingNumber(): string {
191-
const routingNumber = this.faker.string.numeric({
192-
length: 8,
191+
const federalReserveRoutingSymbol = this.faker.helpers.arrayElement(
192+
this.faker.definitions.finance.federal_reserve_routing_symbol
193+
);
194+
195+
const institutionIdentifier = this.faker.string.numeric({
196+
length: 4,
193197
allowLeadingZeros: true,
194198
});
195199

200+
const routingNumber = federalReserveRoutingSymbol + institutionIdentifier;
201+
196202
// Modules 10 straight summation.
197203
let sum = 0;
198204

test/modules/__snapshots__/finance.spec.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ exports[`finance > 42 > pin > with length 1`] = `"3975110867"`;
7575

7676
exports[`finance > 42 > pin > with length option 1`] = `"3975110867"`;
7777

78-
exports[`finance > 42 > routingNumber 1`] = `"397511082"`;
78+
exports[`finance > 42 > routingNumber 1`] = `"062197511"`;
7979

8080
exports[`finance > 42 > transactionDescription 1`] = `"You made a withdrawal of SAR 598.66 at Streich - Aufderhar using card ending in ****9821 from account ***1354."`;
8181

@@ -156,7 +156,7 @@ exports[`finance > 1211 > pin > with length 1`] = `"9829667368"`;
156156

157157
exports[`finance > 1211 > pin > with length option 1`] = `"9829667368"`;
158158

159-
exports[`finance > 1211 > routingNumber 1`] = `"982966738"`;
159+
exports[`finance > 1211 > routingNumber 1`] = `"122482962"`;
160160

161161
exports[`finance > 1211 > transactionDescription 1`] = `"withdrawal transaction at Paucek - Powlowski using card ending with ****8768 for KES 867.32 in account ***8251."`;
162162

@@ -237,7 +237,7 @@ exports[`finance > 1337 > pin > with length 1`] = `"2124352971"`;
237237

238238
exports[`finance > 1337 > pin > with length option 1`] = `"2124352971"`;
239239

240-
exports[`finance > 1337 > routingNumber 1`] = `"212435298"`;
240+
exports[`finance > 1337 > routingNumber 1`] = `"051412430"`;
241241

242242
exports[`finance > 1337 > transactionDescription 1`] = `"Payment of CAD 278.12 for invoice at Wolf - Howe, processed with card ending ****6194 linked to account ***7734."`;
243243

test/modules/finance.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isAbaRouting } from 'validator';
12
import isCreditCard from 'validator/lib/isCreditCard';
23
import isLuhnNumber from 'validator/lib/isLuhnNumber';
34
import { describe, expect, it } from 'vitest';
@@ -139,10 +140,22 @@ describe('finance', () => {
139140
});
140141

141142
describe('routingNumber()', () => {
142-
it('should return a string', () => {
143+
it('should return a valid ABA routing number', () => {
143144
const routingNumber = faker.finance.routingNumber();
144145

145146
expect(routingNumber).toBeTypeOf('string');
147+
expect(routingNumber).toSatisfy(isAbaRouting);
148+
});
149+
150+
it('should correspond to a valid federal reserve district', () => {
151+
const routingNumber = faker.finance.routingNumber();
152+
153+
const firstTwoDigits = routingNumber.substring(0, 2);
154+
const federalReserveDistrict = Number.parseInt(firstTwoDigits);
155+
156+
expect(federalReserveDistrict).toBeTypeOf('number');
157+
expect(federalReserveDistrict).toBeGreaterThan(0);
158+
expect(federalReserveDistrict).toBeLessThanOrEqual(12);
146159
});
147160
});
148161

0 commit comments

Comments
 (0)