# to-arabic-numbers

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

Latest version **2.0.1** (published 2026-04-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install to-arabic-numbers
pnpm add to-arabic-numbers
yarn add to-arabic-numbers
bun add to-arabic-numbers
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2026-04-11 |
| First published | 2022-03-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 0 |
| Unpacked size | 13.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Mohamed Nashaat |
| Maintainers | nashaatfarrag |
| Keywords | arabic, arabic-numbers, persian, farsi, number, numbers, convert, to-arabic-numbers, arabic-indic, digits, english-to-arabic, arabic-to-english, persian-numbers, i18n, internationalization, localization |

## Links

- npm: https://www.npmjs.com/package/to-arabic-numbers
- Repository: https://github.com/Arabic-tools/to-arabic-numbers
- Homepage: https://github.com/Arabic-tools/to-arabic-numbers#readme
- Issues: https://github.com/Arabic-tools/to-arabic-numbers/issues
- npm.io page: https://npm.io/package/to-arabic-numbers

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2026-04-11
- 2.0.0 — 2026-04-11
- 1.0.4 — 2023-06-19
- 1.0.3 — 2022-03-27
- 1.0.2 — 2022-03-12
- 1.0.1 — 2022-03-12
- 1.0.0 — 2022-03-12

## README

# to-arabic-numbers

[![npm version](https://img.shields.io/npm/v/to-arabic-numbers.svg)](https://www.npmjs.com/package/to-arabic-numbers)
[![license](https://img.shields.io/npm/l/to-arabic-numbers.svg)](https://github.com/Arabic-tools/to-arabic-numbers/blob/main/LICENSE)
[![npm downloads](https://img.shields.io/npm/dm/to-arabic-numbers.svg)](https://www.npmjs.com/package/to-arabic-numbers)

> 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 / التثبيت

```bash
# npm
npm install to-arabic-numbers

# yarn
yarn add to-arabic-numbers

# pnpm
pnpm add to-arabic-numbers
```

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

### CommonJS

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

### ES Modules

```js
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.

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

### `convertNumbers2Arabic(input)`

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

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

### `convertNumbers2Persian(input)`

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

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

### `convertPersian2English(input)`

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

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

### `hasArabicNumbers(input)`

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

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

### `hasPersianNumbers(input)`

Returns `true` if the string contains any **Persian** digits.

```js
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`.

```ts
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](https://github.com/Arabic-tools/to-arabic-numbers).

## 📄 License

[MIT](./LICENSE) © Mohamed Nashaat

---
_Source: https://npm.io/package/to-arabic-numbers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
