Skip to content

toQuranicBrackets

Homayoun edited this page Jul 10, 2026 · 1 revision

Introduced in v1.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 parentheses () into ornate Quranic brackets ο΄Ώ ο΄Ύ. This function is highly requested for Quranic applications, Islamic texts, and religious publications where standard parentheses look visually out of place next to Arabic script.

Because this function is designed for Right-to-Left (RTL) text, it correctly maps the standard opening parenthesis ( to the visual right-side bracket ο΄Ώ (U+FD3F), and the standard closing parenthesis ) to the visual left-side bracket ο΄Ύ (U+FD3E).

πŸ“ Syntax

toQuranicBrackets(text: string): string

Parameters

Name Type Description
text string The text containing standard parentheses to convert.

Returns

  • string : Returns the text with standard parentheses replaced by ornate Quranic brackets. Returns the original string unchanged if it is empty, null, or contains no standard parentheses.

πŸ’‘ Examples

Basic Usage

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

toQuranicBrackets("(Ψ§Ω„Ψ¨Ω‚Ψ±Ψ©)");         
// Output: "ο΄ΏΨ§Ω„Ψ¨Ω‚Ψ±Ψ©ο΄Ύ"

toQuranicBrackets("سورة الفاΨͺΨ­Ψ© (1)"); 
// Output: "سورة الفاΨͺΨ­Ψ© ο΄Ώ1ο΄Ύ"

toQuranicBrackets("Hello (world)");    
// Output: "Hello ο΄Ώworldο΄Ύ" (Note: visually flipped in RTL context)

Real-World Quranic Context

When rendering verse numbers or Surah names, standard parentheses often look too small or disconnected from the Arabic text. Quranic brackets provide a much more professional and traditional appearance:

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

const verseNumber = toArabicDigits("(255)"); // "(Ω’Ω₯Ω₯)"
const quranicVerse = toQuranicBrackets(verseNumber); 
// Output: "ο΄ΏΩ’Ω₯Ω₯ο΄Ύ" (Ayat al-Kursi verse number)

βš™οΈ Technical Details & Compatibility

  • RTL Visual Ordering: In standard LTR typing, you type ( then text then ). In an RTL context, the opening bracket appears on the right, and the closing bracket appears on the left. This function maps:
    • ( (U+0028) βž” ο΄Ώ (U+FD3E ORNATE LEFT PARENTHESIS / visually right in RTL)
    • ) (U+0029) βž” ο΄Ύ (U+FD3F ORNATE RIGHT PARENTHESIS / visually left in RTL)
  • Global Replacement: It uses global regular expressions (/\(/g and /\)/g) to ensure all parentheses in the string are converted, not just the first occurrence.
  • IE11 Compatibility: The function relies on standard String.prototype.replace() and intentionally avoids modern methods like String.prototype.replaceAll() to ensure full compatibility with legacy browsers like IE11.
  • Safe Execution: If the input is falsy (e.g., null, undefined, or ""), it immediately returns the input without throwing an error.

πŸ“œ Version History

  • v1.2.0: Added toQuranicBrackets() to convert standard brackets to ornate Quranic brackets as part of the Arabic enhancements update.

πŸš€ 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