urdu-text-utils 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +39 -2
- package/dist/index.cjs +2053 -292
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +64 -4
- package/dist/index.d.ts +64 -4
- package/dist/index.js +2050 -293
- package/dist/index.js.map +1 -1
- package/package.json +8 -3
package/dist/index.d.cts
CHANGED
|
@@ -110,9 +110,29 @@ declare function hasUrduSpecificLetters(input: string): boolean;
|
|
|
110
110
|
declare function countWords(input: string): number;
|
|
111
111
|
/** The word list behind {@link countWords}. Useful for tokenizing before search or indexing. */
|
|
112
112
|
declare function splitWords(input: string): string[];
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
interface SplitSentenceOptions {
|
|
114
|
+
/** If true, the sentence-ending punctuation (۔ ؟ ! . etc.) is preserved with each sentence. Default `false`. */
|
|
115
|
+
preserveTerminators?: boolean;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Sentences count, split on Urdu and standard terminators (۔ ؟ ! . …).
|
|
119
|
+
* Protects common titles, abbreviations, and numeric decimals from false splits.
|
|
120
|
+
*/
|
|
121
|
+
declare function countSentences(input: string, options?: SplitSentenceOptions): number;
|
|
122
|
+
/**
|
|
123
|
+
* Split text into sentences using Urdu punctuation rules.
|
|
124
|
+
*
|
|
125
|
+
* Handles Urdu full stop `۔`, Arabic question mark `؟`, exclamation `!`,
|
|
126
|
+
* ASCII `.`, `?`, `!`, and ellipses `…`, while protecting abbreviations and numbers.
|
|
127
|
+
*
|
|
128
|
+
* @param input - Input text.
|
|
129
|
+
* @param options - Options controlling termination preservation.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* splitSentences("پاکستان ایک خوبصورت ملک ہے۔ اس کی تاریخ پرانی ہے۔")
|
|
133
|
+
* // ["پاکستان ایک خوبصورت ملک ہے", "اس کی تاریخ پرانی ہے"]
|
|
134
|
+
*/
|
|
135
|
+
declare function splitSentences(input: string, options?: SplitSentenceOptions): string[];
|
|
116
136
|
interface UrduStats {
|
|
117
137
|
/** Every codepoint, including spaces and diacritics. */
|
|
118
138
|
characters: number;
|
|
@@ -137,6 +157,46 @@ interface UrduStats {
|
|
|
137
157
|
*/
|
|
138
158
|
declare function analyzeUrdu(input: string): UrduStats;
|
|
139
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Standard list of Urdu stop words.
|
|
162
|
+
*
|
|
163
|
+
* Covers pronouns, postpositions, auxiliaries, conjunctions, particles,
|
|
164
|
+
* and high-frequency functional words used across Urdu texts.
|
|
165
|
+
* All keys are canonical normalized Urdu.
|
|
166
|
+
*/
|
|
167
|
+
declare const URDU_STOP_WORDS: Set<string>;
|
|
168
|
+
/**
|
|
169
|
+
* Checks if a given Urdu word is a stop word.
|
|
170
|
+
*
|
|
171
|
+
* @param word - Word to test.
|
|
172
|
+
* @param customStopWords - Optional custom stop words set or array. Defaults to {@link URDU_STOP_WORDS}.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* isStopWord("اور") // true
|
|
176
|
+
* isStopWord("کتاب") // false
|
|
177
|
+
*/
|
|
178
|
+
declare function isStopWord(word: string, customStopWords?: Set<string> | string[]): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Filters out stop words from an array of words.
|
|
181
|
+
*
|
|
182
|
+
* @param words - Array of words to filter.
|
|
183
|
+
* @param customStopWords - Optional custom stop words set or array.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* filterStopWords(["یہ", "ایک", "اچھی", "کتاب", "ہے"]) // ["اچھی", "کتاب"]
|
|
187
|
+
*/
|
|
188
|
+
declare function filterStopWords(words: string[], customStopWords?: Set<string> | string[]): string[];
|
|
189
|
+
/**
|
|
190
|
+
* Removes stop words from an Urdu text string, returning the cleaned text.
|
|
191
|
+
*
|
|
192
|
+
* @param text - Input Urdu text.
|
|
193
|
+
* @param customStopWords - Optional custom stop words set or array.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* removeStopWords("یہ ایک بہترین کتاب ہے") // "بہترین کتاب"
|
|
197
|
+
*/
|
|
198
|
+
declare function removeStopWords(text: string, customStopWords?: Set<string> | string[]): string;
|
|
199
|
+
|
|
140
200
|
/**
|
|
141
201
|
* Comparator for Urdu strings, usable directly in `Array.prototype.sort`.
|
|
142
202
|
* Diacritics and Unicode variants are folded first, so spelling noise does not
|
|
@@ -242,4 +302,4 @@ interface SlugOptions {
|
|
|
242
302
|
*/
|
|
243
303
|
declare function urduSlug(input: string, options?: SlugOptions): string;
|
|
244
304
|
|
|
245
|
-
export { type DigitStyle, type IsUrduOptions, type NormalizeOptions, type SearchOptions, type SearchResult, type SlugOptions, type SortOptions, type UrduStats, analyzeUrdu, compareUrdu, convertNumbers, countSentences, countWords, editDistance, foldUrdu, hasUrduSpecificLetters, highlightUrdu, isUrdu, normalizeUrdu, numberToUrduWords, parseUrduNumber, removeDiacritics, romanToUrdu, romanize, searchUrdu, searchUrduRanked, sortUrdu, splitSentences, splitWords, toArabicIndicDigits, toEnglishDigits, toUrduDigits, urduRatio, urduSlug };
|
|
305
|
+
export { type DigitStyle, type IsUrduOptions, type NormalizeOptions, type SearchOptions, type SearchResult, type SlugOptions, type SortOptions, type SplitSentenceOptions, URDU_STOP_WORDS, type UrduStats, analyzeUrdu, compareUrdu, convertNumbers, countSentences, countWords, editDistance, filterStopWords, foldUrdu, hasUrduSpecificLetters, highlightUrdu, isStopWord, isUrdu, normalizeUrdu, numberToUrduWords, parseUrduNumber, removeDiacritics, removeStopWords, romanToUrdu, romanize, searchUrdu, searchUrduRanked, sortUrdu, splitSentences, splitWords, toArabicIndicDigits, toEnglishDigits, toUrduDigits, urduRatio, urduSlug };
|
package/dist/index.d.ts
CHANGED
|
@@ -110,9 +110,29 @@ declare function hasUrduSpecificLetters(input: string): boolean;
|
|
|
110
110
|
declare function countWords(input: string): number;
|
|
111
111
|
/** The word list behind {@link countWords}. Useful for tokenizing before search or indexing. */
|
|
112
112
|
declare function splitWords(input: string): string[];
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
interface SplitSentenceOptions {
|
|
114
|
+
/** If true, the sentence-ending punctuation (۔ ؟ ! . etc.) is preserved with each sentence. Default `false`. */
|
|
115
|
+
preserveTerminators?: boolean;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Sentences count, split on Urdu and standard terminators (۔ ؟ ! . …).
|
|
119
|
+
* Protects common titles, abbreviations, and numeric decimals from false splits.
|
|
120
|
+
*/
|
|
121
|
+
declare function countSentences(input: string, options?: SplitSentenceOptions): number;
|
|
122
|
+
/**
|
|
123
|
+
* Split text into sentences using Urdu punctuation rules.
|
|
124
|
+
*
|
|
125
|
+
* Handles Urdu full stop `۔`, Arabic question mark `؟`, exclamation `!`,
|
|
126
|
+
* ASCII `.`, `?`, `!`, and ellipses `…`, while protecting abbreviations and numbers.
|
|
127
|
+
*
|
|
128
|
+
* @param input - Input text.
|
|
129
|
+
* @param options - Options controlling termination preservation.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* splitSentences("پاکستان ایک خوبصورت ملک ہے۔ اس کی تاریخ پرانی ہے۔")
|
|
133
|
+
* // ["پاکستان ایک خوبصورت ملک ہے", "اس کی تاریخ پرانی ہے"]
|
|
134
|
+
*/
|
|
135
|
+
declare function splitSentences(input: string, options?: SplitSentenceOptions): string[];
|
|
116
136
|
interface UrduStats {
|
|
117
137
|
/** Every codepoint, including spaces and diacritics. */
|
|
118
138
|
characters: number;
|
|
@@ -137,6 +157,46 @@ interface UrduStats {
|
|
|
137
157
|
*/
|
|
138
158
|
declare function analyzeUrdu(input: string): UrduStats;
|
|
139
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Standard list of Urdu stop words.
|
|
162
|
+
*
|
|
163
|
+
* Covers pronouns, postpositions, auxiliaries, conjunctions, particles,
|
|
164
|
+
* and high-frequency functional words used across Urdu texts.
|
|
165
|
+
* All keys are canonical normalized Urdu.
|
|
166
|
+
*/
|
|
167
|
+
declare const URDU_STOP_WORDS: Set<string>;
|
|
168
|
+
/**
|
|
169
|
+
* Checks if a given Urdu word is a stop word.
|
|
170
|
+
*
|
|
171
|
+
* @param word - Word to test.
|
|
172
|
+
* @param customStopWords - Optional custom stop words set or array. Defaults to {@link URDU_STOP_WORDS}.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* isStopWord("اور") // true
|
|
176
|
+
* isStopWord("کتاب") // false
|
|
177
|
+
*/
|
|
178
|
+
declare function isStopWord(word: string, customStopWords?: Set<string> | string[]): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Filters out stop words from an array of words.
|
|
181
|
+
*
|
|
182
|
+
* @param words - Array of words to filter.
|
|
183
|
+
* @param customStopWords - Optional custom stop words set or array.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* filterStopWords(["یہ", "ایک", "اچھی", "کتاب", "ہے"]) // ["اچھی", "کتاب"]
|
|
187
|
+
*/
|
|
188
|
+
declare function filterStopWords(words: string[], customStopWords?: Set<string> | string[]): string[];
|
|
189
|
+
/**
|
|
190
|
+
* Removes stop words from an Urdu text string, returning the cleaned text.
|
|
191
|
+
*
|
|
192
|
+
* @param text - Input Urdu text.
|
|
193
|
+
* @param customStopWords - Optional custom stop words set or array.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* removeStopWords("یہ ایک بہترین کتاب ہے") // "بہترین کتاب"
|
|
197
|
+
*/
|
|
198
|
+
declare function removeStopWords(text: string, customStopWords?: Set<string> | string[]): string;
|
|
199
|
+
|
|
140
200
|
/**
|
|
141
201
|
* Comparator for Urdu strings, usable directly in `Array.prototype.sort`.
|
|
142
202
|
* Diacritics and Unicode variants are folded first, so spelling noise does not
|
|
@@ -242,4 +302,4 @@ interface SlugOptions {
|
|
|
242
302
|
*/
|
|
243
303
|
declare function urduSlug(input: string, options?: SlugOptions): string;
|
|
244
304
|
|
|
245
|
-
export { type DigitStyle, type IsUrduOptions, type NormalizeOptions, type SearchOptions, type SearchResult, type SlugOptions, type SortOptions, type UrduStats, analyzeUrdu, compareUrdu, convertNumbers, countSentences, countWords, editDistance, foldUrdu, hasUrduSpecificLetters, highlightUrdu, isUrdu, normalizeUrdu, numberToUrduWords, parseUrduNumber, removeDiacritics, romanToUrdu, romanize, searchUrdu, searchUrduRanked, sortUrdu, splitSentences, splitWords, toArabicIndicDigits, toEnglishDigits, toUrduDigits, urduRatio, urduSlug };
|
|
305
|
+
export { type DigitStyle, type IsUrduOptions, type NormalizeOptions, type SearchOptions, type SearchResult, type SlugOptions, type SortOptions, type SplitSentenceOptions, URDU_STOP_WORDS, type UrduStats, analyzeUrdu, compareUrdu, convertNumbers, countSentences, countWords, editDistance, filterStopWords, foldUrdu, hasUrduSpecificLetters, highlightUrdu, isStopWord, isUrdu, normalizeUrdu, numberToUrduWords, parseUrduNumber, removeDiacritics, removeStopWords, romanToUrdu, romanize, searchUrdu, searchUrduRanked, sortUrdu, splitSentences, splitWords, toArabicIndicDigits, toEnglishDigits, toUrduDigits, urduRatio, urduSlug };
|