Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

anynum

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anynum

Normalize all Unicode decimal digits (Devanagari, Arabic, Thai, etc.) to ASCII numerals. Zero dependencies, performance-first.

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
4.5M
Maintainers
1
Weekly downloads
 
Created
Source

anynum

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 (09). 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

// ESM
import 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 09 by position.

anynum('๑๒๓')   // Thai        → '123'
anynum('੧੨੩')   // Gurmukhi   → '123'
anynum('᠑᠒᠓')   // Mongolian  → '123'
anynum('𝟏𝟐𝟑')   // Math Bold  → '123'

Unicode minus variants

Three Unicode characters are normalized to ASCII - (U+002D):

Code pointCharacterName
U+2212MINUS SIGN (mathematical)
U+FF0DFULLWIDTH HYPHEN-MINUS
U+FE63SMALL HYPHEN-MINUS

Dashes used for punctuation — EN DASH (), EM DASH (), HYPHEN () — are intentionally not converted.

anynum('−42')   // U+2212 MINUS SIGN      → '-42'
anynum('-42')  // U+FF0D FULLWIDTH        → '-42'
anynum('–42')   // U+2013 EN DASH          → '–42'  (unchanged)

Use with strnum

anynum and strnum compose cleanly:

import anynum from 'anynum';
import strnum from 'strnum';

strnum(anynum('१२.३४'))   // → 12.34  (number, float)
strnum(anynum('−४२'))     // → '-42'  (string; strnum handles sign detection)
strnum(anynum('hello'))   // → 'hello'

Supported scripts

50+ decimal digit scripts from Unicode Nd category, including:

ScriptZeroSample
Devanagari (Hindi/Marathi/Nepali)U+0966०१२३४५६७८९
Arabic-IndicU+0660٠١٢٣٤٥٦٧٨٩
Extended Arabic-Indic (Urdu/Persian)U+06F0۰۱۲۳۴۵۶۷۸۹
BengaliU+09E6০১২৩৪৫৬৭৮৯
GurmukhiU+0A66੦੧੨੩੪੫੬੭੮੯
GujaratiU+0AE6૦૧૨૩૪૫૬૭૮૯
OdiaU+0B66୦୧୨୩୪୫୬୭୮୯
TamilU+0BE6௦௧௨௩௪௫௬௭௮௯
TeluguU+0C66౦౧౨౩౪౫౬౭౮౯
KannadaU+0CE6೦೧೨೩೪೫೬೭೮೯
MalayalamU+0D66൦൧൨൩൪൫൬൭൮൯
ThaiU+0E50๐๑๒๓๔๕๖๗๘๙
LaoU+0ED0໐໑໒໓໔໕໖໗໘໙
TibetanU+0F20༠༡༢༣༤༥༦༧༨༩
MyanmarU+1040၀၁၂၃၄၅၆၇၈၉
KhmerU+17E0០១២៣៤៥៦៧៨៩
MongolianU+1810᠐᠑᠒᠓᠔᠕᠖᠗᠘᠙
Fullwidth (CJK context)U+FF100123456789
Mathematical BoldU+1D7CE𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗
AdlamU+1E950𞥐𞥑𞥒𞥓𞥔𞥕𞥖𞥗𞥘𞥙
… and 30+ more

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.
  • Roman numerals (, ) — not decimal digits.
  • Punctuation dashes ( EN, EM, HYPHEN) — not numeric signs.
  • Decimal separators — commas, periods, Arabic decimal comma (٫) are passed through as-is. Separator normalization is the caller's responsibility.

License

MIT

Keywords

unicode

FAQs

Package last updated on 09 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts