Skip to content

normalizeTehMarbuta

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 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.

πŸ“ Syntax

normalizeTehMarbuta(text: string): string

Parameters

Name Type Description
text string The text containing Arabic Teh Marbuta to normalize to Persian Heh.

Returns

  • 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.

πŸ’‘ Examples

Basic Usage

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

// Arabic Teh Marbuta (Ψ©) -> Persian Heh (Ω‡)
normalizeTehMarbuta("Ψ±Ψ³Ψ§Ω„Ψ©");   // "Ψ±Ψ³Ψ§Ω„Ω‡"
normalizeTehMarbuta("Ψ΄Ψ¬Ψ±Ψ©");    // "Ψ΄Ψ¬Ψ±Ω‡"
normalizeTehMarbuta("ΨΉΨ§Ψ¦Ω„Ψ©");   // "ΨΉΨ§Ψ¦Ω„Ω‡"

// Already correct Persian text remains unchanged
normalizeTehMarbuta("Ω†Ψ§Ω…Ω‡");    // "Ω†Ψ§Ω…Ω‡"

Fixing Font Rendering and Spellchecking

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)

🌍 Character Mapping

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

βš™οΈ Technical Details & Compatibility

  • 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 u regex 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.

πŸ“œ Version History

  • v1.2.0: Added normalizeTehMarbuta() as part of the Persian language enhancements to fix common Arabic character intrusions and improve font rendering.

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