autoConvertDigitsToEN helper that normalizes any input to English digits.
The three systems
| System | Sample | Unicode range |
|---|---|---|
| English (Latin) | 0123456789 | U+0030 – U+0039 |
| Persian (Farsi) | ۰۱۲۳۴۵۶۷۸۹ | U+06F0 – U+06F9 |
| Arabic-Indic | ٠١٢٣٤٥٦٧٨٩ | U+0660 – U+0669 |
Converters
autoConvertDigitsToEN is the right default when ingesting unknown user input (form field, copy-paste, OCR).
Input rules and errors
digitsEnToFa/digitsEnToAracceptstring | number. Anything else throwsTypeError("PersianTools: digitsEnToFa - The input must be string or number")(and similarly fordigitsEnToAr).digitsFaToEn,digitsFaToAr,digitsArToEn,digitsArToFaacceptstring. Anything else throwsTypeError("PersianTools: <fn> - The input must be string").autoConvertDigitsToENpasses falsy input through as-is (no throw).
Exported constants
Types
Pitfalls
- The strict converters throw on
null/undefined/ wrong types — they do NOT gracefully return"". Wrap intry/catchor guard upstream. digitsFaToEnleaves Arabic digits untouched. UseautoConvertDigitsToENfor mixed input.- Hand-rolling with
String.fromCharCodemath is fragile — the Persian and Arabic ranges sit at different offsets. Use these functions.
Source
src/modules/digits/ (converters/, digits.constants.ts) · Tests: test/digits.spec.ts