getBankNameFromCardNumber
BusinessgetBankNameFromCardNumber is an Agent Skill for business published in the persian-tools/persian-tools repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Resolve the issuing Iranian bank's Persian name from a card number by looking up its 6-digit BIN prefix. Use when displaying "Card from بانک سامان" next to a captured card number. Triggers on mentions of getBankNameFromCardNumber, bank from card, BIN lookup, نام بانک از شماره کارت.
QUICK START
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/persian-tools/persian-tools/blob/HEAD/skills/getBankNameFromCardNumber/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/getbanknamefromcardnumber, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
getBankNameFromCardNumber — bank name from card BIN
import { getBankNameFromCardNumber } from "@persian-tools/persian-tools";
// CommonJS
const { getBankNameFromCardNumber } = require("@persian-tools/persian-tools");
Public export
getBankNameFromCardNumber(digits?: number | string): string | null | undefined
interface IBank {
code: string;
name: string;
}
Behaviour
import { getBankNameFromCardNumber } from "@persian-tools/persian-tools";
getBankNameFromCardNumber("6219861034529007"); // "بانک سامان"
getBankNameFromCardNumber("603799"); // "بانک ملی ایران" — accepts BIN-only (≥ 6 digits)
getBankNameFromCardNumber("123"); // null — too short
getBankNameFromCardNumber("9999999999999999"); // null — BIN not in cardBank table
getBankNameFromCardNumber(undefined); // undefined
Algorithm
- Falsy input →
undefined. - Stringified length must be in
[6, 16]. Outside that range →null. - Take the leading 6 characters as the BIN.
- Look up
cardBank[bin]from the data table (src/modules/getBankNameFromCardNumber/banksCode.skip.ts). - Return the bank's Persian name or
nullif the BIN isn't mapped.
Return-type triple
undefined= falsy input, we didn't even try.null= ran the lookup, BIN unknown or wrong length.string= bank's Persian name.
Use === "string" or an explicit null/undefined check; don't truthy-test alone.
Quirks
- Does NOT validate the card. It only inspects the BIN. A garbage tail (e.g.
"603799 garbage") doesn't matter as long as the leading 6 chars match a known BIN AND total length ∈ [6, 16]. - Persian/Arabic digit input is NOT normalized. Lookup is keyed by English-digit string. Pre-normalize with
autoConvertDigitsToENif needed. - The data table is stored under
banksCode.skip.ts(the.skipsuffix marks it as a heavy data file — see thebundle-size-guardianskill in.agents/).
Adding a new bank
- Add its BIN entries to
cardBankinbanksCode.skip.ts. - Add the same BIN(s) to
iranianBankPrefixesinsrc/modules/verifyCardNumber/constants.tssoverifyCardNumberaccepts cards from the new issuer. - Add a test case in
test/getBankNameFromCardNumber.spec.tsandtest/verifyCardNumber.spec.ts.
References
- Tests:
test/getBankNameFromCardNumber.spec.ts - Related:
verifyCardNumberskill (validates),extractCardNumbersskill (extracts from free text)