@smakss/convert-numbers converts Arabic-Indic and Persian digits to English digits while preserving the rest of your text.
Try the CodeSandbox demo, or run the local playground included in this repository.
npm install @smakss/convert-numbers
# or
pnpm add @smakss/convert-numbersFor ECMAScript modules:
import convertNumbers from '@smakss/convert-numbers';
console.log(convertNumbers('۱۲۳۴۵۶۷۸۹۰')); // '1234567890'
console.log(convertNumbers('رقم الطلب: ١٢٣-٤٥٦')); // 'رقم الطلب: 123-456'
console.log(convertNumbers('')); // ''For CommonJS:
const { default: convertNumbers } = require('@smakss/convert-numbers');
console.log(convertNumbers('٤٥٦')); // '456'- Converts Arabic-Indic digits (
٠–٩) and Persian digits (۰–۹). - Preserves surrounding text, punctuation, spacing, and other digits.
- Includes ESM, CommonJS, and TypeScript declaration entrypoints.
- Supports Node.js 18 and later, as well as browsers.
The Vite playground imports this package through the pnpm workspace, so you can try local changes without publishing a version:
pnpm install
pnpm run dev:playgroundBuild the playground with pnpm run build:playground.
See CONTRIBUTING.md for development and pull request guidelines.
Please read our Code of Conduct before participating.