-
Notifications
You must be signed in to change notification settings - Fork 0
normalizeArabicYeh
β οΈ 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.
Normalizes the Arabic letter Alef Maqsura (Ω) to the standard Yeh (Ω). In many Arabic dialects (such as Egyptian) and common typing habits, Alef Maqsura is used interchangeably with Yeh at the end of words. Normalizing these characters ensures consistent search results, accurate text comparison, and standardized data storage.
normalizeArabicYeh(text: string): string| Name | Type | Description |
|---|---|---|
text |
string |
The Arabic text containing Alef Maqsura to normalize. |
-
string: Returns the text with all instances of Alef Maqsura (Ω) converted to standard Yeh (Ω). Returns the original string unchanged if it is empty,null, or contains no Alef Maqsura.
import { normalizeArabicYeh } from 'rtl-text-tools';
normalizeArabicYeh("ΨΉΩΩ"); // "ΨΉΩΩ" (Alef Maqsura -> standard Yeh)
normalizeArabicYeh("Ω
Ψ΅Ψ±Ω"); // "Ω
Ψ΅Ψ±Ω" (Common Egyptian spelling -> standard)
normalizeArabicYeh("ΩΨ°Ω"); // "ΩΨ°Ψ§" -> wait, "ΩΨ°Ω" (End of word Yeh)
normalizeArabicYeh("ΩΩΨ³Ω"); // "ΩΩΨ³Ω" (Already standard Yeh -> unchanged)When building a search feature or filtering data, users might type words with different Yeh variations depending on their regional dialect or keyboard layout. Normalizing both the database text and the user's query ensures accurate matches:
import { normalizeArabicYeh } from 'rtl-text-tools';
const databaseText = "ΨΉΩΩ"; // Stored with standard Yeh
const userQuery = "ΨΉΩΩ"; // User typed with Alef Maqsura
const normalizedDB = normalizeArabicYeh(databaseText); // "ΨΉΩΩ"
const normalizedQuery = normalizeArabicYeh(userQuery); // "ΨΉΩΩ"
if (normalizedDB === normalizedQuery) {
console.log("Match found!"); // This will now successfully match
}This function specifically targets the following Unicode character and replaces it with the standard Yeh (\u064A):
| Original Character | Name | Unicode | Replaced With |
|---|---|---|---|
| Ω | Alef Maqsura | \u0649 |
Ω (\u064A) |
-
Direct Replacement: The function uses a standard
String.prototype.replace()method with a global regular expression (/\u0649/g) to ensure every instance of the targeted character is replaced. -
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
normalizeArabicYeh()as part of the Arabic language enhancements for deep text normalization.
π 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!