Skip to main content
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). Use 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, set formal: true.
  • Numbers ≥ 1000 are not multiplied in colloquial mode ("دو هزار تومن" is 2000, not 2,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