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.
32 lines (31 loc) • 1.24 kB
TypeScript
export interface IsUrduOptions {
/**
* Minimum share of Arabic-script letters among all letters, 0-1. Default `0.5`.
* A ratio rather than "contains any Urdu" so that a mostly-English string with
* one Urdu word does not count as Urdu.
*/
threshold?: number;
/** Require at least this many Arabic-script letters. Default `1`. */
minLetters?: number;
}
/**
* Ratio of Arabic-script letters to all letters, 0-1.
* Returns 0 for text with no letters at all (digits, punctuation, emoji).
*/
export declare function urduRatio(input: string): number;
/**
* Is this text Urdu (more precisely: predominantly Arabic-script)?
*
* The Arabic script is shared by Urdu, Arabic, Persian, Pashto and others, so
* this cannot distinguish Urdu from Arabic on script alone. Use
* {@link hasUrduSpecificLetters} when that distinction matters.
*
* @example
* isUrdu("آپ کیسے ہیں؟") // true
*/
export declare function isUrdu(input: string, options?: IsUrduOptions): boolean;
/**
* True when the text contains at least one letter that Arabic does not use.
* Cheap way to separate Urdu/Persian-family text from Arabic text.
*/
export declare function hasUrduSpecificLetters(input: string): boolean;