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.

53 lines (52 loc) • 2.42 kB
/** Words in the text. Splits on whitespace and punctuation, so `ہے۔` counts once. */ export declare function countWords(input: string): number; /** The word list behind {@link countWords}. Useful for tokenizing before search or indexing. */ export declare function splitWords(input: string): string[]; export interface SplitSentenceOptions { /** If true, the sentence-ending punctuation (۔ ؟ ! . etc.) is preserved with each sentence. Default `false`. */ preserveTerminators?: boolean; } /** Common Urdu abbreviations and honorifics that should not cause false sentence splits. */ export declare const SENTENCE_ABBREVIATIONS: string[]; /** * Sentences count, split on Urdu and standard terminators (۔ ؟ ! . …). * Protects common titles, abbreviations, and numeric decimals from false splits. */ export declare function countSentences(input: string, options?: SplitSentenceOptions): number; /** * Split text into sentences using Urdu punctuation rules. * * Handles Urdu full stop `۔`, Arabic question mark `؟`, exclamation `!`, * ASCII `.`, `?`, `!`, and ellipses `…`, while protecting abbreviations and numbers. * * @param input - Input text. * @param options - Options controlling termination preservation. * * @example * splitSentences("پاکستان ایک خوبصورت ملک ہے۔ اس کی تاریخ پرانی ہے۔") * // ["پاکستان ایک خوبصورت ملک ہے", "اس کی تاریخ پرانی ہے"] */ export declare function splitSentences(input: string, options?: SplitSentenceOptions): string[]; export interface UrduStats { /** Every codepoint, including spaces and diacritics. */ characters: number; charactersNoSpaces: number; words: number; sentences: number; /** Whitespace-delimited blocks separated by a blank line. */ paragraphs: number; /** Share of Arabic-script letters among all letters, 0-100, rounded. */ urduPercentage: number; diacritics: number; digits: number; averageWordsPerSentence: number; /** At 180 Urdu words per minute — slower than English because the script is denser. */ readingTimeMinutes: number; } /** * Character, word, sentence and script statistics for a block of text. * * @example * analyzeUrdu("پاکستان ایک خوبصورت ملک ہے۔ اس کی آبادی زیادہ ہے۔") */ export declare function analyzeUrdu(input: string): UrduStats;