-
Notifications
You must be signed in to change notification settings - Fork 0
toQuranicBrackets
β οΈ Version Recommendation: Always install and use the latest version ofrtl-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).
toQuranicBrackets(text: string): string| Name | Type | Description |
|---|---|---|
text |
string |
The text containing standard parentheses to convert. |
-
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.
import { toQuranicBrackets } from 'rtl-text-tools';
toQuranicBrackets("(Ψ§ΩΨ¨ΩΨ±Ψ©)");
// Output: "ο΄ΏΨ§ΩΨ¨ΩΨ±Ψ©ο΄Ύ"
toQuranicBrackets("Ψ³ΩΨ±Ψ© Ψ§ΩΩΨ§ΨͺΨΨ© (1)");
// Output: "Ψ³ΩΨ±Ψ© Ψ§ΩΩΨ§ΨͺΨΨ© ο΄Ώ1ο΄Ύ"
toQuranicBrackets("Hello (world)");
// Output: "Hello ο΄Ώworldο΄Ύ" (Note: visually flipped in RTL 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)-
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 (
/\(/gand/\)/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 likeString.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.
-
v1.2.0: Added
toQuranicBrackets()to convert standard brackets to ornate Quranic brackets as part of the Arabic enhancements update.
π Home β’ π Getting Started β’ π API Reference β’ π Report Issue
Made with β€οΈ by Homayoun Mohammadi
If you find this project useful, please consider β starring the repo to show your support!
- π Home
- π Getting Started
- π§© API Overview
- π οΈ Framework Guides
- π‘ Use Cases
- π₯οΈ Browser Compatibility
- β FAQ & Troubleshooting
Homayoun Mohammadi
π GitHub β’ βοΈ Email
β Love this project? Star it on GitHub to show your support!