Skip to main content
Arabic text normalization is essential for accurate search matching. The library provides two normalization functions that handle diacritics, Unicode variants, and character unification.

Overview

The normalization module exports two primary functions:
  • removeTashkeel() - Removes diacritics and Quranic marks
  • normalizeArabic() - Advanced normalization for search indexing

Remove diacritics

removeTashkeel(text: string): string

Removes Tashkeel (diacritics) and Quranic marks from Arabic text. Use case: Stripping diacritics for display or simple comparisons.

What it removes

From src/utils/normalization.ts:7-11:
The function removes:
  • Wasl alef (converts to regular alef)
  • All diacritical marks (Unicode range \u064B-\u065F)
  • Quranic annotation marks
  • Superscript alef

Advanced normalization

normalizeArabic(text: string): string

Advanced Arabic normalization for search indexing. Handles Unicode normalization, variant unification, and cleanup. Use case: Preparing user input for searching (unifies alef variants, removes tashkeel, etc).

Normalization steps

1

Remove diacritics

Calls removeTashkeel() to strip all diacritical marks and applies Unicode NFC normalization.
2

Remove special characters

Removes dagger alif and tatweel (elongation character).
3

Unify alef variants

Normalizes all alef variants to a single form.
Converts: إ أ آ ٱ → ا
4

Unify hamza variants

Normalizes hamza on different carriers to standalone hamza.
Converts: ؤ ئ → ء
5

Unify ya variants

Converts alif maqsura to regular ya.
Converts: ى → ي
6

Clean whitespace and control characters

Removes line breaks, non-Arabic characters, and normalizes whitespace.
7

Trim and return

Removes leading and trailing whitespace.

Full implementation

From src/utils/normalization.ts:20-43:
The normalizeArabic() function is used internally throughout the search engine to ensure consistent matching:
Always normalize both the search query and the text being searched to ensure accurate matching regardless of input variations.

Character unification table

Empty input strings return empty strings - the function gracefully handles null or undefined input.