Skip to content

fixHebrewFinalForms

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.

Fixes Hebrew final letter forms (known as Sofit letters).

In Hebrew, five specific letters change their shape when they appear at the end of a word. If text is typed incorrectly (e.g., using a regular form at the end of a word, or a final form in the middle), it looks visually wrong and can break spellcheckers. This function automatically corrects these letters based on their position in the word.

Crucially, it is "Niqqud-aware": it correctly looks past vowel marks (diacritics) to determine the actual end of the word without stripping or breaking the vowels.

πŸ“ Syntax

fixHebrewFinalForms(text: string): string

Parameters

Name Type Description
text string The Hebrew text to normalize.

Returns

  • string : Returns the text with corrected Hebrew final forms. Returns the original string unchanged if it is empty, null, or contains no target letters.

πŸ’‘ Examples

Basic Usage

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

// 1. Fixing incorrect regular forms at the end of a word
fixHebrewFinalForms("Χ™Χ¨Χ•Χ©ΧœΧ™Χ‘"); // "Χ™Χ¨Χ•Χ©ΧœΧ™Χ" (Regular Tsade -> Final Tsade)
fixHebrewFinalForms("שלם");     // "שלם" (Regular Mem -> Final Mem)

// 2. Fixing incorrect final forms in the middle of a word
fixHebrewFinalForms("םכנב");    // "ΧžΧ›Χ Χ‘" (Final Mem -> Regular Mem)
fixHebrewFinalForms("Χ‘Χ™ΧšΧ•Χ¨");   // "Χ‘Χ™Χ›Χ•Χ¨" (Final Kaf -> Regular Kaf)

// 3. Correct text remains unchanged
fixHebrewFinalForms("Χ©ΧœΧ•Χ");    // "Χ©ΧœΧ•Χ"

Handling Niqqud (Vowel Marks)

The function intelligently skips over diacritics when looking ahead to see if a letter is at the end of a word. This ensures that vocalized text (like poetry or religious texts) is corrected without destroying the vowel marks.

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

// The function sees the Tsade, looks past the Niqqud, sees no more Hebrew letters, 
// and correctly converts it to the final form (Χ₯).
fixHebrewFinalForms("Χ™Φ°Χ¨Χ•ΦΌΧ©ΦΈΧΧœΦ·Χ™Φ΄Χ‘"); // "Χ™Φ°Χ¨Χ•ΦΌΧ©ΦΈΧΧœΦ·Χ™Φ΄Χ" 

🌍 Character Mapping (The 5 Sofit Letters)

This function targets the 5 Hebrew letters that have distinct final forms, correcting them in both directions:

Regular Form Final Form (Sofit) Hebrew Name
Χ› (Kaf) ך (Kaf Sofit) Kaf
מ (Mem) ם (Mem Sofit) Mem
נ (Nun) ן (Nun Sofit) Nun
Χ€ (Pe) Χ£ (Pe Sofit) Pe
Χ¦ (Tsade) Χ₯ (Tsade Sofit) Tsade

βš™οΈ Technical Details & Compatibility

  • Context-Aware Lookahead: The function iterates through the string and looks ahead to find the next actual Hebrew letter. If it encounters Niqqud (Unicode range \u0590-\u05CF), it skips over them to accurately determine if the current letter is truly at the end of the word.
  • Bidirectional Correction: Unlike simple regex replacements, this function fixes both incorrect final forms in the middle of words AND incorrect regular forms at the end of words.
  • IE11 Compatibility: It uses standard string iteration and character indexing, avoiding modern ES6+ features like Array.from() or the u regex flag 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 fixHebrewFinalForms() as part of the Hebrew language enhancements to ensure correct typographic rendering of Sofit letters.

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