Skip to content

API Reference

Homayoun edited this page Jul 10, 2026 · 3 revisions

Welcome to the API Reference for rtl-text-tools.

This section provides comprehensive documentation for every function available in the library. Click on any function name to view its detailed parameters, return types, and usage examples.

🧩 Core Functions

The main entry points for text detection, normalization, and all-in-one processing.

  • hasRTL() — Detect if text contains Right-to-Left characters.
  • hasHebrew() — Specifically detect Hebrew characters.
  • fixRTL() — The main function that applies all RTL text fixes at once. (Features strict TypeScript intellisense that adapts options based on the selected language).

🔍 Language Detection

Detect specific RTL languages and regional scripts beyond standard Arabic and Hebrew.

🔢 Digit Conversion

Utilities for converting standard Latin numerals (0-9) into localized digit formats, including smart decimal handling.

  • toArabicDigits() — Convert to Arabic-Indic numerals (٠–٩).
  • toPersianDigits() — Convert to Extended Persian numerals (۰–۹).
  • toPersianDecimal() — Smart decimal conversion that safely ignores IP addresses and version numbers (e.g., 192.168.1.1, 1.2.0) to prevent unwanted conversions.

🔣 Punctuation & Brackets

Tools for fixing, converting, and repositioning punctuation marks and brackets for proper RTL rendering.

  • convertPunctuation() — Convert , ; ? to RTL equivalents ، ؛ ؟. (Smart: Automatically skips Hebrew text to preserve Western punctuation).
  • fixBracket() — Convert and fix brackets for general RTL or specific Arabic contexts.
  • moveEllipsis() — Move trailing ... or to the start of RTL text.
  • toQuranicBrackets() — Convert standard brackets to Quranic brackets ﴿ ﴾ for Arabic text.

🌍 Language-Specific Normalizers

Deep normalization utilities tailored for the unique typographic rules of specific RTL languages.

🇸🇦 Arabic

🇮🇷 Persian

🇮🇱 Hebrew

🇵🇰 Urdu

🎨 Bidi & Styling

Helpers for managing bidirectional (bidi) text rendering in plain-text contexts, applying CSS styles, and manipulating DOM attributes.

  • wrapRTL() — Wrap text with Unicode bidi control characters to force RTL rendering.
  • wrapLTR() — Wrap text with Unicode bidi control characters to force LTR rendering.
  • getRTLStyles() — Get a ready-to-use { direction, unicodeBidi } style object for RTL.
  • getLTRStyles() — Get a ready-to-use { direction, unicodeBidi } style object for LTR.
  • setDirAttribute() — Set dir and lang attributes directly on DOM elements.

💡 Need Help?

If you can't find what you're looking for in the API documentation, check out the FAQ & Troubleshooting page or open an issue on GitHub.

🚀 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