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.
65 lines (64 loc) • 2.48 kB
TypeScript
/**
* Urdu script -> Roman Urdu.
*
* Best-effort Urdu -> Roman Urdu using a dictionary and spelling rules.
* Unseen words may be ambiguous because Urdu omits short vowels; punctuation,
* digits, and non-Urdu text are preserved.
* @example
* romanize("آپ کیسے ہیں") // "aap kaisay hain"
*/
export declare function romanize(input: string, options?: {
capitalize?: boolean;
}): string;
export interface NormalizeRomanUrduOptions {
/**
* Case-insensitive spelling overrides and additions. Built-in aliases can be
* overridden for a project's preferred spelling.
*/
customVariants?: Readonly<Record<string, string>>;
}
/**
* Canonicalizes known Roman Urdu spelling variants without translating words.
*
* Only unambiguous aliases of at least three letters are normalized by default;
* short spellings are left alone because they commonly overlap with English.
* Pass `customVariants` to add or override spellings for a known corpus.
*
* @example
* normalizeRomanUrdu("hay, kese ho?") // "hai, kaisay ho?"
*/
export declare function normalizeRomanUrdu(input: string, options?: NormalizeRomanUrduOptions): string;
/**
* Roman Urdu -> Urdu script.
*
* Uses known dictionary spellings first, then approximate letter rules for
* unknown words. Roman Urdu has no standard spelling, so ambiguous input and
* unknown words cannot be converted reliably. Punctuation, whitespace, digits,
* and non-Latin characters are preserved.
*
* @example
* romanToUrdu("mera naam zaid hai") // "میرا نام زید ہے"
*/
export declare function romanToUrdu(input: string): string;
export interface SlugOptions {
/** Word separator. Default `"-"`. */
separator?: string;
/** Cap the slug length, cutting at a word boundary. */
maxLength?: number;
/**
* Keep Urdu characters instead of transliterating. Produces a percent-encoded
* but human-readable URL, and avoids the accuracy problem entirely. Default `false`.
*/
preserveUrdu?: boolean;
}
/**
* URL slug from an Urdu title.
*
* @experimental in transliterating mode, for the reasons in the module note.
* Pass `preserveUrdu: true` for a lossless slug.
*
* @example
* urduSlug("میرا پہلا مضمون") // "mera-pehla-mazmoon"
* urduSlug("میرا پہلا مضمون", { preserveUrdu: true }) // "میرا-پہلا-مضمون"
*/
export declare function urduSlug(input: string, options?: SlugOptions): string;