UNPKG

urdu-text-utils

Version:

Comprehensive Urdu NLP & text processing toolkit: normalization, Roman Urdu transliteration, stop words, script detection, digits, diacritics (aerab), sorting, search, and statistics. Zero dependencies, ESM + CJS.

39 lines (38 loc) • 1.67 kB
import type { DigitStyle } from "./numbers.js"; export interface NormalizeOptions { /** Apply Unicode NFKC first, folding presentation forms (ﻻ, ﮐ) back to real letters. Default `true`. */ compatibility?: boolean; /** Strip harakat and quranic marks. Default `false` — see {@link removeDiacritics}. */ stripDiacritics?: boolean; /** Remove tatweel/kashida padding. Default `true`. */ stripTatweel?: boolean; /** Remove zero-width non-joiner. Default `false`, since ZWNJ can be meaningful. */ stripZwnj?: boolean; /** Collapse whitespace runs to a single space and trim. Default `true`. */ collapseWhitespace?: boolean; /** Rewrite every digit to one style. Default `"preserve"`. */ digits?: DigitStyle | "preserve"; /** Map ASCII `,` `;` `?` to Urdu `،` `؛` `؟`. Default `false`. */ urduPunctuation?: boolean; } /** * Fold an Urdu string to a single canonical Unicode form. * * @example * normalizeUrdu("كيا حال ہے") // "کیا حال ہے" */ export declare function normalizeUrdu(input: string, options?: NormalizeOptions): string; /** * Strip harakat, quranic annotation marks and superscript alef. * Keeps ۔ ے ۓ, which are letters/punctuation rather than marks. * * @example * removeDiacritics("مُحَمَّد") // "محمد" */ export declare function removeDiacritics(input: string): string; /** * The comparison key used by {@link searchUrdu} and {@link sortUrdu}: * normalized, diacritic-free, lowercased, whitespace-collapsed. * Two strings that a reader would call "the same word" should fold to the same key. */ export declare function foldUrdu(input: string): string;