-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
45 lines (37 loc) · 1.17 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { institutions } from './institutions.js'
import {
formatBankNumber,
institutionNumberLength,
transitNumberLength
} from './utilities.js'
/**
* @param institutionNumber - A three-digit Canadian bank institution number.
* @param [transitNumber] - A five-digit Canadian bank transit (branch) number.
* @returns - A Canadian bank name.
*/
export default function getCanadianBankName(
institutionNumber: string | number,
transitNumber: string | number = '00000'
): string | undefined {
// eslint-disable-next-line @typescript-eslint/init-declarations
let bankName: string | undefined
const institutionNumberString = formatBankNumber(
institutionNumber,
institutionNumberLength
)
if (institutionNumberString === undefined) {
return undefined
}
const transitNumberString = formatBankNumber(
transitNumber,
transitNumberLength
)
if (transitNumberString !== undefined) {
bankName = institutions[`${transitNumberString}-${institutionNumberString}`]
}
if (bankName === undefined) {
bankName = institutions[`00000-${institutionNumberString}`]
}
return bankName
}
export { institutionCommonNames } from './institutions.js'