-
Notifications
You must be signed in to change notification settings - Fork 0
removeUrduDiacritics
β οΈ 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.
Removes Urdu-specific diacritics, including the unique Ghunna mark (Ω), along with standard Arabic diacritics (Harakat).
The Ghunna mark (U+06D8) is unique to Urdu and indicates a specific nasal sound. This function strips these marks out to leave the clean, base text, which is highly useful for search indexing, text comparison, and normalizing user input.
β οΈ Important Warning: Do not use this function if you are processing Quranic texts, classical poetry, or children's books where vowel marks and nasalization are strictly required for correct pronunciation and meaning.
removeUrduDiacritics(text: string): string| Name | Type | Description |
|---|---|---|
text |
string |
The text containing Urdu/Arabic diacritics to remove. |
-
string: Returns the text with all diacritics in the\u064Bto\u065Frange, as well as the Urdu Ghunna mark (\u06D8), stripped out. Returns the original string unchanged if it is empty,null, or contains no diacritics.
import { removeUrduDiacritics } from 'rtl-text-tools';
removeUrduDiacritics("ΩΎΩΨ§Ϊ©"); // "ΩΎΨ§Ϊ©" (Fatha removed)
removeUrduDiacritics("Ψ§ΩΨ±Ψ―ΩΩ"); // "Ψ§Ψ±Ψ―Ω" (Damma and Urdu Ghunna mark removed)
removeUrduDiacritics("Ψ±ΩΨΩ
Ψ§Ω"); // "Ψ±ΨΩ
Ψ§Ω" (Ghunna mark removed)
removeUrduDiacritics("Ψ¨Ψ―ΩΩ Ψ§ΨΉΨ±Ψ§Ψ¨"); // "Ψ¨Ψ―ΩΩ Ψ§ΨΉΨ±Ψ§Ψ¨" (No diacritics = unchanged)When building a search feature for Urdu, users will almost never type diacritics or the Ghunna mark. Stripping these from your database content ensures that searches match regardless of how the text was originally vocalized:
import { removeUrduDiacritics } from 'rtl-text-tools';
const databaseText = "Ψ±ΩΨΩ
Ψ§Ω"; // Vocalized text with Ghunna from a database
const userQuery = "Ψ±ΨΩ
Ψ§Ω"; // User typed without diacritics
const normalizedDB = removeUrduDiacritics(databaseText); // "Ψ±ΨΩ
Ψ§Ω"
const normalizedQuery = removeUrduDiacritics(userQuery); // "Ψ±ΨΩ
Ψ§Ω"
if (normalizedDB === normalizedQuery) {
console.log("Match found!"); // This will now successfully match
}This function targets the standard Arabic diacritics block plus the specific Urdu Ghunna mark:
| Character | Name | Unicode |
|---|---|---|
| Ω | Fathatan | \u064B |
| Ω | Dammatan | \u064C |
| Ω | Kasratan | \u064D |
| Ω | Fatha | \u064E |
| Ω | Damma | \u064F |
| Ω | Kasra | \u0650 |
| Ω | Shadda | \u0651 |
| Ω | Sukun | \u0652 |
| (and others) | Small high ligatures, Maddah, etc. |
\u0653 - \u065F
|
| Ω | Ghunna Mark (Urdu) | \u06D8 |
-
Regex Character Class: The function uses a highly efficient regular expression (
/[\u064B-\u065F\u06D8]/g) to match the entire range of standard diacritics and the specific Urdu Ghunna mark in a single pass, replacing them with an empty string''. - Base Characters Preserved: It strictly targets the combining marks. Base letters (like Alef, Ba, Noon Ghunna, etc.) are completely untouched.
-
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
removeUrduDiacritics()as part of the new Urdu language support to clean up text for search and 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!