Skip to content
Merged
7 changes: 7 additions & 0 deletions src/definitions/finance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 and symbol (e.g. `US Dollar` / `USD` / `$`).
*/
Expand Down
168 changes: 168 additions & 0 deletions src/locales/base/finance/federal_reserve_routing_symbol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
// Source: https://www.frbservices.org/resources/fees/check-key-to-routing-numbers.html
// Last Synced with Source: 2025-03-01
Comment thread
ST-DDT marked this conversation as resolved.
Outdated
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',
];
12 changes: 12 additions & 0 deletions src/locales/base/finance/index.ts
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions src/locales/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -21,6 +22,7 @@ const base: LocaleDefinition = {
color,
database,
date,
finance,
hacker,
internet,
location,
Expand Down
10 changes: 8 additions & 2 deletions src/modules/finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,17 @@ export class FinanceModule extends ModuleBase {
* @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;

Expand Down
6 changes: 3 additions & 3 deletions test/modules/__snapshots__/finance.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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 Crist - Beer using card ending in ****8670 from account ***9821."`;

Expand Down Expand Up @@ -170,7 +170,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 Zieme - Osinski using card ending with ****6736 for SZL 768.50 in account ***6848."`;

Expand Down Expand Up @@ -258,7 +258,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 Leannon - Gibson, processed with card ending ****9713 linked to account ***6194."`;

Expand Down
18 changes: 16 additions & 2 deletions test/modules/finance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isAbaRouting } from 'validator';
import isCreditCard from 'validator/lib/isCreditCard';
import { describe, expect, it } from 'vitest';
import { faker, fakerZH_CN } from '../../src';
Expand Down Expand Up @@ -149,11 +150,24 @@ describe('finance', () => {
});

describe('routingNumber()', () => {
it('should return a string', () => {
const routingNumber = faker.finance.routingNumber();
const routingNumber = faker.finance.routingNumber();

const firstTwoDigits = routingNumber.substring(0, 2);
const federalReserveDistrict = Number.parseInt(firstTwoDigits);
Comment thread
ST-DDT marked this conversation as resolved.
Outdated

it('should return a string', () => {
expect(routingNumber).toBeTypeOf('string');
});

it('should pass check digit validation', () => {
expect(routingNumber).toSatisfy(isAbaRouting);
});
Comment thread
ST-DDT marked this conversation as resolved.
Outdated

it('should correspond to a valid federal reserve district', () => {
expect(federalReserveDistrict).toBeTypeOf('number');
expect(federalReserveDistrict).toBeGreaterThan(0);
expect(federalReserveDistrict).toBeLessThanOrEqual(12);
});
});

describe('maskedNumber()', () => {
Expand Down