Skip to content

toArabicDigits

Homayoun edited this page Jul 9, 2026 · 1 revision

Introduced in v0.2.0

⚠️ Version Recommendation: Always install and use the latest version of rtl-text-tools (npm install rtl-text-tools@latest). While this specific feature was introduced in an earlier version, the latest release includes crucial bug fixes, better edge-case handling, and improved legacy browser compatibility. Avoid pinning your project to an old version just to use this function.

Converts standard Latin digits (0-9) into Arabic-Indic numerals (Ω -Ω©). This is the standard digit format used in Arabic, Egyptian, and most Middle Eastern locales.

(Note: If you need Persian/Urdu digits instead, use toPersianDigits(). If you are using the main fixRTL() function with lang: 'arabic', this conversion is applied automatically.)

πŸ“ Syntax

toArabicDigits(text: string): string

Parameters

Name Type Description
text string The text containing Latin digits to convert.

Returns

  • string : The text with all Latin digits replaced by Arabic-Indic numerals. Returns the original string unchanged if it is empty, null, or contains no digits.

πŸ’‘ Examples

Basic Usage

import { toArabicDigits } from 'rtl-text-tools';

toArabicDigits("Price 123");     // "Price Ω‘Ω’Ω£"
toArabicDigits("Year 2024");     // "Year Ω’Ω Ω’Ω€"
toArabicDigits("Hello world");   // "Hello world" (No digits to convert)
toArabicDigits("");              // "" (Empty string)

Mixed Content

It safely ignores non-digit characters and only transforms the numbers:

import { toArabicDigits } from 'rtl-text-tools';

toArabicDigits("Total: $50.00"); 
// Output: "Total: $Ω₯Ω .Ω Ω "

βš™οΈ Technical Details & Compatibility

  • IE11 Compatibility: The function uses the standard String.prototype.replace() method with a regular expression and a callback function. It intentionally avoids modern methods like String.prototype.replaceAll() to ensure full compatibility with legacy browsers like IE11.
  • Performance: It uses a direct character lookup map (ARABIC_DIGITS) inside the replace callback, making the conversion extremely fast even for large strings.
  • Safe Execution: If the input is falsy (e.g., null, undefined, or ""), it immediately returns the input without throwing an error.

πŸ“œ Version History

  • v0.2.0: Added toArabicDigits() to convert Latin numbers to Arabic-Indic numerals (Ω -Ω©).

πŸš€ rtl-text-tools

npm downloads

πŸ‘¨β€πŸ’» Created by

Homayoun Mohammadi
πŸ”— GitHub β€’ βœ‰οΈ Email

⭐ Love this project? Star it on GitHub to show your support!

Clone this wiki locally