Skip to content

removePersianDiacritics

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 Arabic diacritics (Harakat / E'rab) from the text.

Persian rarely uses vowel marks (Fatha, Kasra, Damma, Sukun, etc.) in standard writing. This function strips them 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 are strictly required for correct pronunciation and meaning.

πŸ“ Syntax

removePersianDiacritics(text: string): string

Parameters

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

Returns

  • string : Returns the text with all diacritics in the \u064B to \u065F range stripped out. Returns the original string unchanged if it is empty, null, or contains no diacritics.

πŸ’‘ Examples

Basic Usage

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

removePersianDiacritics("Ω…ΩΨ­ΩŽΩ…ΩŽΩ‘Ψ―");       // "Ω…Ψ­Ω…Ψ―"
removePersianDiacritics("Ψ§ΩŽΩ„Ω’Ψ­ΩŽΩ…Ω’Ψ―Ω Ω„ΩΩ„ΩŽΩ‘Ω‡Ω");  // "Ψ§Ω„Ψ­Ω…Ψ― Ω„Ω„Ω‡"
removePersianDiacritics("شَجَرَةٌ");        // "شجرة" (Teh Marbuta is kept, only diacritics removed)
removePersianDiacritics("Ψ¨Ψ―ΩˆΩ† Ψ§ΨΉΨ±Ψ§Ψ¨");      // "Ψ¨Ψ―ΩˆΩ† Ψ§ΨΉΨ±Ψ§Ψ¨" (No diacritics = unchanged)

Search and Text Comparison

When building a search feature for Persian or Arabic, users will almost never type diacritics. Stripping diacritics from your database content ensures that searches match regardless of how the text was originally vocalized:

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

const databaseText = "كِΨͺَابٌ Ω…ΩΩΩΩŠΨ―ΩŒ"; // Vocalized text from a database
const userQuery = "Ϊ©ΨͺΨ§Ψ¨ Ω…ΩΫŒΨ―";          // User typed without diacritics

const normalizedDB = removePersianDiacritics(databaseText); // "ΩƒΨͺΨ§Ψ¨ Ω…ΩΩŠΨ―"
const normalizedQuery = removePersianDiacritics(userQuery); // "Ϊ©ΨͺΨ§Ψ¨ Ω…ΩΫŒΨ―"

// Note: You might also want to combine this with normalizePersianChars() 
// to handle the Yeh/Kaf differences before comparing!

🌍 Removed Diacritics (Unicode Range)

This function targets the Unicode block from \u064B to \u065F, which includes the most common Arabic vowel marks and signs:

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

βš™οΈ Technical Details & Compatibility

  • Regex Character Class: The function uses a highly efficient regular expression (/[\u064B-\u065F]/g) to match the entire range of diacritics in a single pass, replacing them with an empty string ''.
  • Base Characters Preserved: It strictly targets the combining marks. Base letters (like Alef, Ba, Teh Marbuta, 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 removePersianDiacritics() as part of the Persian language enhancements 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