moneyWordsToNumber parses Persian money expressions — formal ("یک میلیون تومان") and colloquial ("سه تومن", with implicit ×1000 multiplier) — into a number. It auto-detects toman/rial, can convert between them, and tolerates Persian/Arabic digits plus Arabic-keyboard characters.
Functions
moneyWordsToNumber(moneyWords, options?)
Main entry point.
rialsWordsToNumber(text, options?)
Convenience wrapper: hard-codes from: "rial".
tomansWordsToNumber(text, options?)
Convenience wrapper: hard-codes from: "toman".
Options
formal — colloquial vs. formal
Iranian colloquial speech routinely uses تومن with an implicit ×1000 multiplier when the leading number is small (< 1000).
| Phrase | formal: false (default) | formal: true |
|---|---|---|
"یک تومان" | 1 | 1 |
"یک تومن" | 1000 | 1 |
"دویست تومن" | 200000 | 200 |
"دو هزار تومن" | 2000 | 2000 |
formal: true for invoice text or legal contexts. Default suits voice transcripts and chat input.
Cross-currency conversion
Auto-normalization (on by default)
autoConvertDigitsToEn: true→ input may use"یک هزار ۲۰۰ تومان","یک هزار ٢٠٠ تومان", etc.autoConvertArabicCharsToPersian: true→ Arabic-keyboardك/يare corrected to Persianک/یbefore word lookup.
fuzzy
When true, common Persian typos are corrected via the underlying wordsToNumber fuzzy mode. Slower and less deterministic — use for voice/OCR input.
Returns
number. No formatted-string options here — pipe through addCommas for display:
Pitfalls
- Default mode is colloquial (
formal: false). For invoices/contracts, setformal: true. - Numbers ≥ 1000 are not multiplied in colloquial mode (
"دو هزار تومن"is2000, not2,000,000). - Mixed-unit phrases like
"یک تومان و ده ریال"are not supported. - Currency keywords are stripped before parsing — the remaining words are passed to
wordsToNumber.
Source
src/modules/moneyWordsToNumber/index.ts · Tests: test/moneyWordsToNumber.spec.ts