getBankNameFromCardNumber returns the Persian name of the bank that issued an Iranian card, by inspecting the leading 6-digit BIN.
Function
Return type — three states
| Return | Meaning |
|---|---|
string | Issuing bank’s Persian name |
null | Length out of [6, 16], or BIN not in the data table |
undefined | Falsy input — function did not attempt the lookup |
=== "string" rather than a truthy check.
Behaviour
- Falsy input →
undefined. - Stringified length must be in
[6, 16]. Otherwise →null. - Take the leading 6 characters as the BIN.
- Look up in the
cardBankdata table (src/modules/getBankNameFromCardNumber/banksCode.skip.ts). - Return the Persian bank name or
null.
Pitfalls
- This is a lookup, not a validator. A nonsense tail (e.g.
"603799 garbage") doesn’t matter as long as the BIN matches AND total length is in range. For checksum validation, useverifyCardNumber. - Persian/Arabic digit input is not normalized. Pre-convert with
digitsFaToEn/autoConvertDigitsToENif input may contain them. - The data table is curated; new banks may not appear until added.
Composition with verifyCardNumber
Source
src/modules/getBankNameFromCardNumber/index.ts · Tests: test/getBankNameFromCardNumber.spec.ts