Skip to content

removeUrduDiacritics

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.

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.

πŸ“ Syntax

removeUrduDiacritics(text: string): string

Parameters

Name Type Description
text string The text containing Urdu/Arabic diacritics to remove.

Returns

  • string : Returns the text with all diacritics in the \u064B to \u065F range, as well as the Urdu Ghunna mark (\u06D8), stripped out. Returns the original string unchanged if it is empty, null, or contains no diacritics.

πŸ’‘ Examples

Basic Usage

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

removeUrduDiacritics("پَاک");         // "پاک" (Fatha removed)
removeUrduDiacritics("اُردو٘");        // "اردو" (Damma and Urdu Ghunna mark removed)
removeUrduDiacritics("Ψ±Ω˜Ψ­Ω…Ψ§Ω†");        // "Ψ±Ψ­Ω…Ψ§Ω†" (Ghunna mark removed)
removeUrduDiacritics("Ψ¨Ψ―ΩˆΩ† Ψ§ΨΉΨ±Ψ§Ψ¨");    // "Ψ¨Ψ―ΩˆΩ† Ψ§ΨΉΨ±Ψ§Ψ¨" (No diacritics = unchanged)

Search and Text Comparison

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
}

🌍 Removed Diacritics (Unicode Range)

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

βš™οΈ Technical Details & Compatibility

  • 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 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 removeUrduDiacritics() as part of the new Urdu language support to clean up text for search and normalization.

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