npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

to-arabic-numbers

v2.0.1

Published

Convert numbers between Western (English), Arabic-Indic, and Persian (Farsi) numeral systems. Lightweight, zero-dependency, with full TypeScript support.

Readme

to-arabic-numbers

npm version license npm downloads

Lightweight, zero-dependency utility to convert numbers between Western (English), Arabic-Indic, and Persian (Farsi) numeral systems.

أداة خفيفة الوزن، لا تعتمد على أي مكتبات خارجية، لتحويل الأرقام بين الأنظمة الغربية (الإنجليزية)، العربية-الهندية، والفارسية.

✨ Features / المميزات

  • 🔄 Convert between Western ↔ Arabic-Indic ↔ Persian digits (تحويل متبادل بين الأرقام الإنجليزية ↔ العربية والهندية ↔ الفارسية)
  • 🔍 Detect the presence of Arabic or Persian digits in a string (اكتشاف وجود أرقام عربية أو فارسية في النصوص)
  • 🛡️ Safe input handling — null, undefined, and numbers are handled gracefully (معالجة آمنة للمدخلات)
  • 📦 Zero dependencies (لا يعتمد على أي مكتبات خارجية)
  • 📝 Full TypeScript support out of the box (دعم كامل لـ TypeScript)
  • 🔀 Dual CommonJS / ESM module support (يدعم كلا من CommonJS و ESM)

📦 Installation / التثبيت

# npm
npm install to-arabic-numbers

# yarn
yarn add to-arabic-numbers

# pnpm
pnpm add to-arabic-numbers

🚀 Usage / الاستخدام

CommonJS

const {
  convertNumbers2English,
  convertNumbers2Arabic,
  convertNumbers2Persian,
  convertPersian2English,
  hasArabicNumbers,
  hasPersianNumbers,
} = require('to-arabic-numbers');

ES Modules

import {
  convertNumbers2English,
  convertNumbers2Arabic,
  convertNumbers2Persian,
  convertPersian2English,
  hasArabicNumbers,
  hasPersianNumbers,
} from 'to-arabic-numbers';

📖 API / الواجهة البرمجية

convertNumbers2English(input)

Converts Arabic-Indic (٠-٩) and Persian (۰-۹) digits to Western (0-9) digits.

convertNumbers2English('١٢٣');          // '123'
convertNumbers2English('۴۵۶');          // '456'
convertNumbers2English('١٢٣ abc ۴۵۶'); // '123 abc 456'

convertNumbers2Arabic(input)

Converts Western (0-9) digits to Arabic-Indic (٠-٩) digits.

convertNumbers2Arabic('123');           // '١٢٣'
convertNumbers2Arabic('item 1, item 2'); // 'item ١, item ٢'

convertNumbers2Persian(input)

Converts Western (0-9) digits to Persian/Farsi (۰-۹) digits.

convertNumbers2Persian('123');          // '۱۲۳'
convertNumbers2Persian('price: 100');   // 'price: ۱۰۰'

convertPersian2English(input)

Converts Persian (۰-۹) digits to Western (0-9) digits. Does not touch Arabic-Indic digits.

convertPersian2English('۱۲۳');          // '123'
convertPersian2English('٠١٢');          // '٠١٢' (unchanged — these are Arabic-Indic)

hasArabicNumbers(input)

Returns true if the string contains any Arabic-Indic digits.

hasArabicNumbers('hello ١٢٣');  // true
hasArabicNumbers('hello 123');  // false
hasArabicNumbers('hello ۱۲۳');  // false (these are Persian)

hasPersianNumbers(input)

Returns true if the string contains any Persian digits.

hasPersianNumbers('hello ۱۲۳');  // true
hasPersianNumbers('hello 123');  // false
hasPersianNumbers('hello ١٢٣');  // false (these are Arabic-Indic)

🛡️ Input Handling

All functions handle edge cases gracefully:

| Input | Behavior | |-------|----------| | string | Converted normally | | number | Auto-converted to string first | | null | Returns '' (empty string) | | undefined | Returns '' (empty string) |

🏗️ TypeScript

This package includes built-in type declarations. No need to install @types/to-arabic-numbers.

import { convertNumbers2Arabic } from 'to-arabic-numbers';

const result: string = convertNumbers2Arabic('123'); // '١٢٣'

🤝 Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

📄 License

MIT © Mohamed Nashaat