extractCardNumber (singular) finds Iranian card numbers inside free-form text — chat logs, OCR output, payment confirmations — with eight type-narrowing overloads based on option combinations.
The exported function isextractCardNumber(singular). There is noextractCardNumbersplural export, and noextractCardNumberWithMetrics.
Basic usage
Result shape
Every match has at minimum:checkValidation: true→isValid: booleandetectBankNumber: true→bankName: string | nullincludeContext: true→context: { before, after }
Multi-format input
Persian (۰-۹) and Arabic-Indic (٠-٩) digits, plus dashes / underscores / spaces, are recognized and normalized into pure:
Fuzzy matching for masked cards
fuzzyCardNumberRegex to tolerate *, ?, and similar masking. Slower; gate by shouldUseFuzzyMatching(text, config) on large inputs.
Large-text optimization
splitTextIntoChunks (with chunk size from getOptimalChunkConfig) to avoid regex backtracking across the whole document.
Context capture
Type narrowing overloads
The function exposes 8 overloads:ExtractCardNumberOptions, ExtractCardNumberComplete, ExtractCardNumberWithBank, etc.).
Re-exported helpers and constants
Pitfalls
- No metrics function exists. Time the call yourself if you need throughput data.
nullis not in the TS signature, though the runtime guard returns[]for falsy. Pass a string.- Use
pure(notbase) when piping intoverifyCardNumber/getBankNameFromCardNumber.
Source
src/modules/extractCardNumbers/index.ts, types.ts, utils.ts, constants.ts · Tests: test/extractCardNumber.spec.ts