Normalize Unicode decimal digits and minus signs to ASCII.
Converts digits from any script — Devanagari, Arabic-Indic, Thai, Bengali, Fullwidth, and 50+ others — to their ASCII equivalents (0–9). Also normalizes Unicode minus variants (−, -, ﹣) to ASCII -.
Pairs naturally with strnum — use anynum to normalize first, then strnum to detect the numeric type.
import anynum from 'anynum';anynum('१२.३४') // → '12.34' (Devanagari)anynum('٣٫١٤') // → '3.14' (Arabic-Indic)anynum('−४२') // → '-42' (Unicode minus + Devanagari)anynum('-99.5') // → '-99.5' (Fullwidth minus + Fullwidth digits)anynum('hello') // → 'hello' (no digits — zero allocation)anynum('100') // → '100' (already ASCII — zero allocation)
Install
npm install anynum
Usage
// ESMimport anynum from 'anynum';import { anynum } from 'anynum';
API
anynum(str: string): string
Accepts a string, returns a string.
Non-string values are returned as-is (no throw).
Non-digit characters pass through unchanged.
If no conversion is needed, the original string is returned (zero allocation).
What gets converted
Decimal digits
Any Unicode character in category Nd (decimal digit) is mapped to its ASCII equivalent. This covers all positional decimal digit scripts — every script whose digits represent 0–9 by position.
50+ decimal digit scripts from Unicode Nd category, including:
Script
Zero
Sample
Devanagari (Hindi/Marathi/Nepali)
U+0966
०१२३४५६७८९
Arabic-Indic
U+0660
٠١٢٣٤٥٦٧٨٩
Extended Arabic-Indic (Urdu/Persian)
U+06F0
۰۱۲۳۴۵۶۷۸۹
Bengali
U+09E6
০১২৩৪৫৬৭৮৯
Gurmukhi
U+0A66
੦੧੨੩੪੫੬੭੮੯
Gujarati
U+0AE6
૦૧૨૩૪૫૬૭૮૯
Odia
U+0B66
What it does NOT convert
Kanji/Chinese numeral words (三, 百, 万) — these are ideographic numerals, not decimal digits. Each language has its own positional system requiring separate parsing logic.