-
Notifications
You must be signed in to change notification settings - Fork 0
fixHebrewFinalForms
β οΈ 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.
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.
fixHebrewFinalForms(text: string): string| Name | Type | Description |
|---|---|---|
text |
string |
The Hebrew text to normalize. |
-
string: Returns the text with corrected Hebrew final forms. Returns the original string unchanged if it is empty,null, or contains no target letters.
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("Χ©ΧΧΧ"); // "Χ©ΧΧΧ"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("ΧΦ°Χ¨ΧΦΌΧ©ΦΈΧΧΦ·ΧΦ΄Χ‘"); // "ΧΦ°Χ¨ΧΦΌΧ©ΦΈΧΧΦ·ΧΦ΄Χ" 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 |
-
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 theuregex 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.
-
v1.2.0: Added
fixHebrewFinalForms()as part of the Hebrew language enhancements to ensure correct typographic rendering of Sofit letters.
π 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!