-
Notifications
You must be signed in to change notification settings - Fork 0
normalizeTehMarbuta
β οΈ 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 the Arabic Teh Marbuta (Ψ©) to the Persian Heh (Ω).
In Persian, words that end with an "eh" sound (like Ψ±Ψ³Ψ§ΩΩ or ΩΨ§Ω Ω) must use the standard Heh. The Teh Marbuta is strictly an Arabic character; using it in Persian text breaks cursive font rendering, causes visual inconsistencies, and confuses Persian spellcheckers. This function ensures your Persian text is typographically correct.
normalizeTehMarbuta(text: string): string| Name | Type | Description |
|---|---|---|
text |
string |
The text containing Arabic Teh Marbuta to normalize to Persian Heh. |
-
string: Returns the text with all instances of Teh Marbuta (Ψ©) converted to the standard Heh (Ω). Returns the original string unchanged if it is empty,null, or contains no Teh Marbuta.
import { normalizeTehMarbuta } from 'rtl-text-tools';
// Arabic Teh Marbuta (Ψ©) -> Persian Heh (Ω)
normalizeTehMarbuta("Ψ±Ψ³Ψ§ΩΨ©"); // "Ψ±Ψ³Ψ§ΩΩ"
normalizeTehMarbuta("Ψ΄Ψ¬Ψ±Ψ©"); // "Ψ΄Ψ¬Ψ±Ω"
normalizeTehMarbuta("ΨΉΨ§Ψ¦ΩΨ©"); // "ΨΉΨ§Ψ¦ΩΩ"
// Already correct Persian text remains unchanged
normalizeTehMarbuta("ΩΨ§Ω
Ω"); // "ΩΨ§Ω
Ω"When processing user-generated content or importing data from Arabic sources, Teh Marbuta might slip into Persian text. This causes premium Persian fonts (like Vazirmatn or IranSans) to render the character incorrectly or disconnect it from the previous letter.
import { normalizeTehMarbuta, fixRTL } from 'rtl-text-tools';
const rawPersianText = "Ψ§ΫΩ ΫΪ© Ψ±Ψ³Ψ§ΩΨ© Ω
ΩΩ
Ψ§Ψ³Ψͺ"; // Contains Arabic Ψ©
// Normalize the character, then apply standard RTL fixes
const cleanText = fixRTL(normalizeTehMarbuta(rawPersianText));
// Output: "Ψ§ΫΩ ΫΪ© Ψ±Ψ³Ψ§ΩΩ Ω
ΩΩ
Ψ§Ψ³Ψͺ" (Now renders perfectly and passes spellcheck)This function specifically targets the following Arabic character and replaces it with the standard Persian Heh:
| Original Character | Name | Unicode | Replaced With | Persian Name |
|---|---|---|---|---|
| Ψ© | Teh Marbuta | \u0629 |
Ω (\u0647) |
Heh / Doachashmee |
-
Direct Replacement: The function uses a standard
String.prototype.replace()method with a global regular expression (/\u0629/g) to ensure every instance of the targeted character is replaced. - Typography Preservation: By converting this character, you ensure that the text will correctly connect and render according to Persian typographic rules, which is crucial for professional UI design and accurate text processing in Iran.
-
IE11 Compatibility: It avoids modern string methods and the ES6
uregex flag, ensuring 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
normalizeTehMarbuta()as part of the Persian language enhancements to fix common Arabic character intrusions and improve font rendering.
π 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!