cspell-trie-lib 9.0.2 → 9.1.1

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +725 -665
  2. package/dist/index.js +9125 -7310
  3. package/package.json +6 -6
package/dist/index.d.ts CHANGED
@@ -1,756 +1,801 @@
1
- import { SuggestionCostMapDef, DictionaryDefinitionAugmented } from '@cspell/cspell-types';
2
- export { SuggestionCostMapDef } from '@cspell/cspell-types';
3
- import { Operator } from '@cspell/cspell-pipe/sync';
1
+ import { Operator } from "@cspell/cspell-pipe/sync";
2
+ import { DictionaryDefinitionAugmented, SuggestionCostMapDef } from "@cspell/cspell-types";
3
+
4
+ //#region src/lib/distance/weightedMaps.d.ts
4
5
 
5
6
  /**
6
- * Costs are minimized while penalties are maximized.
7
- */
7
+ * Costs are minimized while penalties are maximized.
8
+ */
8
9
  interface Cost$1 {
9
- /**
10
- * The cost of an operation
11
- * `c'' = min(c, c')`
12
- */
13
- c?: number | undefined;
14
- /**
15
- * The penalties applied
16
- * `p'' = max(p, p')`
17
- */
18
- p?: number | undefined;
10
+ /**
11
+ * The cost of an operation
12
+ * `c'' = min(c, c')`
13
+ */
14
+ c?: number | undefined;
15
+ /**
16
+ * The penalties applied
17
+ * `p'' = max(p, p')`
18
+ */
19
+ p?: number | undefined;
19
20
  }
20
21
  interface TrieCost extends Cost$1 {
21
- /** nested trie nodes */
22
- n?: Record<string, TrieCost>;
22
+ /** nested trie nodes */
23
+ n?: Record<string, TrieCost>;
23
24
  }
24
25
  interface TrieTrieCost {
25
- /** nested trie nodes */
26
- n?: Record<string, TrieTrieCost>;
27
- /** root of cost trie */
28
- t?: Record<string, TrieCost>;
26
+ /** nested trie nodes */
27
+ n?: Record<string, TrieTrieCost>;
28
+ /** root of cost trie */
29
+ t?: Record<string, TrieCost>;
29
30
  }
30
31
  interface WeightMap {
31
- readonly insDel: TrieCost;
32
- readonly replace: TrieTrieCost;
33
- readonly swap: TrieTrieCost;
34
- readonly adjustments: Map<string, PenaltyAdjustment>;
32
+ readonly insDel: TrieCost;
33
+ readonly replace: TrieTrieCost;
34
+ readonly swap: TrieTrieCost;
35
+ readonly adjustments: Map<string, PenaltyAdjustment>;
35
36
  }
36
37
  interface PenaltyAdjustment {
37
- /** Penalty Identifier */
38
- id: string;
39
- /** RegExp Pattern to match */
40
- regexp: RegExp;
41
- /** Penalty to apply */
42
- penalty: number;
43
- }
44
-
38
+ /** Penalty Identifier */
39
+ id: string;
40
+ /** RegExp Pattern to match */
41
+ regexp: RegExp;
42
+ /** Penalty to apply */
43
+ penalty: number;
44
+ }
45
+ //#endregion
46
+ //#region src/lib/distance/distance.d.ts
45
47
  /**
46
- * Calculate the edit distance between any two words.
47
- * Use the Damerau–Levenshtein distance algorithm.
48
- * @param wordA
49
- * @param wordB
50
- * @param editCost - the cost of each edit (defaults to 100)
51
- * @returns the edit distance.
52
- */
48
+ * Calculate the edit distance between any two words.
49
+ * Use the Damerau–Levenshtein distance algorithm.
50
+ * @param wordA
51
+ * @param wordB
52
+ * @param editCost - the cost of each edit (defaults to 100)
53
+ * @returns the edit distance.
54
+ */
53
55
  declare function editDistance(wordA: string, wordB: string, editCost?: number): number;
54
56
  /**
55
- * Calculate the weighted edit distance between any two words.
56
- * @param wordA
57
- * @param wordB
58
- * @param weights - the weights to use
59
- * @param editCost - the cost of each edit (defaults to 100)
60
- * @returns the edit distance
61
- */
57
+ * Calculate the weighted edit distance between any two words.
58
+ * @param wordA
59
+ * @param wordB
60
+ * @param weights - the weights to use
61
+ * @param editCost - the cost of each edit (defaults to 100)
62
+ * @returns the edit distance
63
+ */
62
64
  declare function editDistanceWeighted(wordA: string, wordB: string, weights: WeightMap, editCost?: number): number;
63
65
  /**
64
- * Collect Map definitions into a single weighted map.
65
- * @param defs - list of definitions
66
- * @returns A Weighted Map to be used with distance calculations.
67
- */
66
+ * Collect Map definitions into a single weighted map.
67
+ * @param defs - list of definitions
68
+ * @returns A Weighted Map to be used with distance calculations.
69
+ */
68
70
  declare function createWeightedMap(defs: SuggestionCostMapDef[]): WeightMap;
69
-
70
71
  /**
71
- * Make all properties in T optional and Possibly undefined
72
- */
73
- type PartialWithUndefined<T> = {
74
- [P in keyof T]?: T[P] | undefined;
75
- };
76
-
72
+ * Update a WeightedMap with a WeightedMapDef
73
+ * @param weightedMap - map to update
74
+ * @param def - the definition to use
75
+ */
76
+ //#endregion
77
+ //#region src/lib/types.d.ts
78
+ /**
79
+ * Make all properties in T optional and Possibly undefined
80
+ */
81
+ type PartialWithUndefined<T> = { [P in keyof T]?: T[P] | undefined };
82
+ /**
83
+ * Make all fields mandatory
84
+ */
85
+ //#endregion
86
+ //#region src/lib/ITrieNode/TrieInfo.d.ts
77
87
  interface TrieInfo {
78
- compoundCharacter: string;
79
- stripCaseAndAccentsPrefix: string;
80
- forbiddenWordPrefix: string;
81
- isCaseAware: boolean;
88
+ compoundCharacter: string;
89
+ stripCaseAndAccentsPrefix: string;
90
+ forbiddenWordPrefix: string;
91
+ isCaseAware: boolean;
82
92
  }
83
93
  interface TrieCharacteristics {
84
- hasForbiddenWords: boolean;
85
- hasCompoundWords: boolean;
86
- hasNonStrictWords: boolean;
94
+ hasForbiddenWords: boolean;
95
+ hasCompoundWords: boolean;
96
+ hasNonStrictWords: boolean;
87
97
  }
88
98
  type PartialTrieInfo = PartialWithUndefined<TrieInfo> | undefined;
89
-
99
+ //#endregion
100
+ //#region src/lib/ITrieNode/ITrieNode.d.ts
90
101
  interface FindResult$1 {
91
- found: string | false;
92
- compoundUsed: boolean;
93
- caseMatched: boolean;
94
- /**
95
- * Is the word explicitly forbidden.
96
- * - `true` - word is in the forbidden list.
97
- * - `false` - word is not in the forbidden list.
98
- * - `undefined` - unknown - was not checked.
99
- */
100
- forbidden?: boolean | undefined;
102
+ found: string | false;
103
+ compoundUsed: boolean;
104
+ caseMatched: boolean;
105
+ /**
106
+ * Is the word explicitly forbidden.
107
+ * - `true` - word is in the forbidden list.
108
+ * - `false` - word is not in the forbidden list.
109
+ * - `undefined` - unknown - was not checked.
110
+ */
111
+ forbidden?: boolean | undefined;
101
112
  }
102
113
  interface FindFullResult$1 extends FindResult$1 {
103
- /**
104
- * Is the word explicitly forbidden.
105
- * - `true` - word is in the forbidden list.
106
- * - `false` - word is not in the forbidden list.
107
- * - `undefined` - unknown - was not checked.
108
- */
109
- forbidden: boolean | undefined;
114
+ /**
115
+ * Is the word explicitly forbidden.
116
+ * - `true` - word is in the forbidden list.
117
+ * - `false` - word is not in the forbidden list.
118
+ * - `undefined` - unknown - was not checked.
119
+ */
120
+ forbidden: boolean | undefined;
110
121
  }
111
122
  type ITrieNodeId = object | number | string;
112
123
  type Entry = readonly [string, ITrieNode];
113
124
  interface ITrieNode {
114
- /**
115
- * ITrieNode instances are not unique. It is possible for multiple ITrieNode instances to
116
- * represent the same node.
117
- * `id` is used to see if two instances refer to the same node.
118
- * The type is obscured because it is up the the backing structure to provide the best value.
119
- * Note, only nodes from the same root are guaranteed to be unique. It is possible for two
120
- * different ITrieNode instances to have the same `id` value if they come from different roots.
121
- */
122
- readonly id: ITrieNodeId;
123
- /** flag End of Word */
124
- readonly eow: boolean;
125
- /** get keys to children */
126
- keys(): Iterable<string>;
127
- /** get keys to children */
128
- values(): Iterable<ITrieNode>;
129
- /** get the children as key value pairs */
130
- entries(): Iterable<Entry>;
131
- /** get child ITrieNode */
132
- get(char: string): ITrieNode | undefined;
133
- /** get a nested child ITrieNode */
134
- getNode?: (chars: string) => ITrieNode | undefined;
135
- /** has child */
136
- has(char: string): boolean;
137
- /** `true` iff this node has children */
138
- hasChildren(): boolean;
139
- /** check if a word exists within this node. */
140
- findExact?: ((word: string) => boolean) | undefined;
125
+ /**
126
+ * ITrieNode instances are not unique. It is possible for multiple ITrieNode instances to
127
+ * represent the same node.
128
+ * `id` is used to see if two instances refer to the same node.
129
+ * The type is obscured because it is up the the backing structure to provide the best value.
130
+ * Note, only nodes from the same root are guaranteed to be unique. It is possible for two
131
+ * different ITrieNode instances to have the same `id` value if they come from different roots.
132
+ */
133
+ readonly id: ITrieNodeId;
134
+ /** flag End of Word */
135
+ readonly eow: boolean;
136
+ /** get keys to children */
137
+ keys(): Iterable<string>;
138
+ /** get keys to children */
139
+ values(): Iterable<ITrieNode>;
140
+ /** get the children as key value pairs */
141
+ entries(): Iterable<Entry>;
142
+ /** get child ITrieNode */
143
+ get(char: string): ITrieNode | undefined;
144
+ /** get a nested child ITrieNode */
145
+ getNode?: (chars: string) => ITrieNode | undefined;
146
+ /** has child */
147
+ has(char: string): boolean;
148
+ /** `true` iff this node has children */
149
+ hasChildren(): boolean;
150
+ /** check if a word exists within this node. */
151
+ findExact?: ((word: string) => boolean) | undefined;
141
152
  }
142
153
  interface ITrieNodeRoot extends ITrieNode {
143
- readonly info: Readonly<TrieInfo>;
144
- /**
145
- * converts an `id` into a node.
146
- * @param id an of a ITrieNode in this Trie
147
- */
148
- resolveId(id: ITrieNodeId): ITrieNode;
149
- findExact: ((word: string) => boolean) | undefined;
150
- /**
151
- * Try to find a word.
152
- * @param word - the normalized word to look up.
153
- * @param strict - if `true` the case and accents must match.
154
- * @returns undefined if it did not try to find the word, otherwise a FindResult.
155
- */
156
- find?: ((word: string, strict: boolean) => FindResult$1 | undefined) | undefined;
157
- isForbidden?: ((word: string) => boolean) | undefined;
158
- readonly forbidPrefix: string;
159
- readonly compoundFix: string;
160
- readonly caseInsensitivePrefix: string;
161
- readonly hasForbiddenWords: boolean;
162
- readonly hasCompoundWords: boolean;
163
- readonly hasNonStrictWords: boolean;
164
- }
165
-
154
+ readonly info: Readonly<TrieInfo>;
155
+ /**
156
+ * converts an `id` into a node.
157
+ * @param id an of a ITrieNode in this Trie
158
+ */
159
+ resolveId(id: ITrieNodeId): ITrieNode;
160
+ findExact: ((word: string) => boolean) | undefined;
161
+ /**
162
+ * Try to find a word.
163
+ * @param word - the normalized word to look up.
164
+ * @param strict - if `true` the case and accents must match.
165
+ * @returns undefined if it did not try to find the word, otherwise a FindResult.
166
+ */
167
+ find?: ((word: string, strict: boolean) => FindResult$1 | undefined) | undefined;
168
+ isForbidden?: ((word: string) => boolean) | undefined;
169
+ readonly forbidPrefix: string;
170
+ readonly compoundFix: string;
171
+ readonly caseInsensitivePrefix: string;
172
+ readonly hasForbiddenWords: boolean;
173
+ readonly hasCompoundWords: boolean;
174
+ readonly hasNonStrictWords: boolean;
175
+ }
176
+ //#endregion
177
+ //#region src/lib/ITrieNode/index.d.ts
166
178
  type TrieOptions = TrieInfo;
167
179
  type TrieOptionsRO = Readonly<TrieOptions>;
168
180
  type PartialTrieOptions = PartialTrieInfo;
169
-
181
+ //#endregion
182
+ //#region src/lib/TrieNode/TrieNode.d.ts
170
183
  declare const FLAG_WORD = 1;
171
184
  type ChildMap = Record<string, TrieNode>;
172
185
  interface TrieNode {
173
- f?: number | undefined;
174
- c?: ChildMap | undefined;
186
+ f?: number | undefined;
187
+ c?: ChildMap | undefined;
175
188
  }
176
189
  interface TrieRoot extends TrieInfo {
177
- c: ChildMap;
190
+ c: ChildMap;
178
191
  }
179
-
192
+ //#endregion
193
+ //#region src/lib/walker/walkerTypes.d.ts
180
194
  declare const JOIN_SEPARATOR = "+";
181
195
  declare const WORD_SEPARATOR = " ";
182
- interface YieldResult$1 {
183
- text: string;
184
- node: TrieNode;
185
- depth: number;
196
+ interface YieldResult {
197
+ text: string;
198
+ node: TrieNode;
199
+ depth: number;
186
200
  }
187
201
  declare enum CompoundWordsMethod {
188
- /**
189
- * Do not compound words.
190
- */
191
- NONE = 0,
192
- /**
193
- * Create word compounds separated by spaces.
194
- */
195
- SEPARATE_WORDS = 1,
196
- /**
197
- * Create word compounds without separation.
198
- */
199
- JOIN_WORDS = 2
200
- }
201
- type WalkerIterator$1 = Generator<YieldResult$1, void, boolean | undefined>;
202
-
203
- interface YieldResult {
204
- text: string;
205
- node: ITrieNode;
206
- depth: number;
202
+ /**
203
+ * Do not compound words.
204
+ */
205
+ NONE = 0,
206
+ /**
207
+ * Create word compounds separated by spaces.
208
+ */
209
+ SEPARATE_WORDS = 1,
210
+ /**
211
+ * Create word compounds without separation.
212
+ */
213
+ JOIN_WORDS = 2,
214
+ }
215
+ type WalkerIterator = Generator<YieldResult, void, boolean | undefined>;
216
+ //#endregion
217
+ //#region src/lib/ITrieNode/walker/walkerTypes.d.ts
218
+ interface YieldResult$1 {
219
+ text: string;
220
+ node: ITrieNode;
221
+ depth: number;
207
222
  }
208
223
  type FalseToNotGoDeeper = boolean;
209
224
  /**
210
- * By default a Walker Iterator will go depth first. To prevent the
211
- * walker from going deeper use `iterator.next(false)`.
212
- */
213
- type WalkerIterator = Generator<YieldResult, void, FalseToNotGoDeeper | undefined>;
214
-
225
+ * By default a Walker Iterator will go depth first. To prevent the
226
+ * walker from going deeper use `iterator.next(false)`.
227
+ */
228
+ type WalkerIterator$1 = Generator<YieldResult$1, void, FalseToNotGoDeeper | undefined>;
229
+ //#endregion
230
+ //#region src/lib/walker/hintedWalker.d.ts
215
231
  /**
216
- * Ask for the next result.
217
- * goDeeper of true tells the walker to go deeper in the Trie if possible. Default is true.
218
- * This can be used to limit the walker's depth.
219
- */
220
- type HintedWalkerIterator = Generator<YieldResult$1, void, Hinting | undefined>;
232
+ * Ask for the next result.
233
+ * goDeeper of true tells the walker to go deeper in the Trie if possible. Default is true.
234
+ * This can be used to limit the walker's depth.
235
+ */
236
+ // next: (hinting?: Hinting) => IteratorResult<YieldResult>;
237
+ // [Symbol.iterator]: () => HintedWalkerIterator;
238
+ type HintedWalkerIterator = Generator<YieldResult, void, Hinting | undefined>;
221
239
  declare function hintedWalker(root: TrieRoot, ignoreCase: boolean, hint: string, compoundingMethod: CompoundWordsMethod | undefined, emitWordSeparator?: string): HintedWalkerIterator;
240
+ /**
241
+ * Walks the Trie and yields a value at each node.
242
+ * next(goDeeper: boolean):
243
+ */
244
+
222
245
  interface Hinting {
223
- goDeeper: boolean;
246
+ goDeeper: boolean;
224
247
  }
225
-
226
- declare function walker(root: TrieNode, compoundingMethod?: CompoundWordsMethod): WalkerIterator$1;
227
-
248
+ //#endregion
249
+ //#region src/lib/walker/walker.d.ts
250
+ declare function walker(root: TrieNode, compoundingMethod?: CompoundWordsMethod): WalkerIterator;
251
+ /**
252
+ * Walks the Trie and yields each word.
253
+ */
254
+ //#endregion
255
+ //#region src/lib/suggestions/genSuggestionsOptions.d.ts
228
256
  interface GenSuggestionOptionsStrict {
229
- /**
230
- * Controls forcing compound words.
231
- * @default CompoundWordsMethod.NONE
232
- */
233
- compoundMethod?: CompoundWordsMethod;
234
- /**
235
- * ignore case when searching.
236
- */
237
- ignoreCase: boolean;
238
- /**
239
- * Maximum number of "edits" allowed.
240
- * 3 is a good number. Above 5 can be very slow.
241
- */
242
- changeLimit: number;
243
- /**
244
- * Inserts a compound character between compounded word segments.
245
- * @default ""
246
- */
247
- compoundSeparator?: string;
257
+ /**
258
+ * Controls forcing compound words.
259
+ * @default CompoundWordsMethod.NONE
260
+ */
261
+ compoundMethod?: CompoundWordsMethod;
262
+ /**
263
+ * ignore case when searching.
264
+ */
265
+ ignoreCase: boolean;
266
+ /**
267
+ * Maximum number of "edits" allowed.
268
+ * 3 is a good number. Above 5 can be very slow.
269
+ */
270
+ changeLimit: number;
271
+ /**
272
+ * Inserts a compound character between compounded word segments.
273
+ * @default ""
274
+ */
275
+ compoundSeparator?: string;
248
276
  }
249
277
  type GenSuggestionOptionsStrictRO = Readonly<GenSuggestionOptionsStrict>;
250
278
  type GenSuggestionOptions = Partial<GenSuggestionOptionsStrict>;
251
279
  type GenSuggestionOptionsRO = Readonly<GenSuggestionOptions>;
252
280
  interface SuggestionOptionsStrict extends GenSuggestionOptionsStrict {
253
- /**
254
- * Maximum number of suggestions to make.
255
- */
256
- numSuggestions: number;
257
- /**
258
- * Allow ties when making suggestions.
259
- * if `true` it is possible to have more than `numSuggestions`.
260
- */
261
- includeTies: boolean;
262
- /**
263
- * Time alloted in milliseconds to generate suggestions.
264
- */
265
- timeout: number;
266
- /**
267
- * Optional filter function.
268
- * return true to keep the candidate.
269
- */
270
- filter?: (word: string, cost: number) => boolean;
271
- /**
272
- * Apply weights to improve the suggestions.
273
- */
274
- weightMap?: WeightMap | undefined;
281
+ /**
282
+ * Maximum number of suggestions to make.
283
+ */
284
+ numSuggestions: number;
285
+ /**
286
+ * Allow ties when making suggestions.
287
+ * if `true` it is possible to have more than `numSuggestions`.
288
+ */
289
+ includeTies: boolean;
290
+ /**
291
+ * Time alloted in milliseconds to generate suggestions.
292
+ */
293
+ timeout: number;
294
+ /**
295
+ * Optional filter function.
296
+ * return true to keep the candidate.
297
+ */
298
+ filter?: (word: string, cost: number) => boolean;
299
+ /**
300
+ * Apply weights to improve the suggestions.
301
+ */
302
+ weightMap?: WeightMap | undefined;
275
303
  }
276
304
  type SuggestionOptions = Partial<SuggestionOptionsStrict>;
277
305
  type SuggestionOptionsRO = Readonly<SuggestionOptions>;
278
-
306
+ //#endregion
307
+ //#region src/lib/suggestions/SuggestionTypes.d.ts
279
308
  type Cost = number;
280
309
  type MaxCost = Cost;
281
310
  interface SuggestionResultBase {
282
- /** The suggested word */
283
- word: string;
284
- /** The edit cost 100 = 1 edit */
285
- cost: Cost;
286
- /**
287
- * This suggestion is the preferred suggestion.
288
- * Setting this to `true` implies that an auto fix is possible.
289
- */
290
- isPreferred?: boolean | undefined;
311
+ /** The suggested word */
312
+ word: string;
313
+ /** The edit cost 100 = 1 edit */
314
+ cost: Cost;
315
+ /**
316
+ * This suggestion is the preferred suggestion.
317
+ * Setting this to `true` implies that an auto fix is possible.
318
+ */
319
+ isPreferred?: boolean | undefined;
291
320
  }
292
321
  interface SuggestionResult extends SuggestionResultBase {
293
- /** The suggested word with compound marks, generally a `•` */
294
- compoundWord?: string | undefined;
322
+ /** The suggested word with compound marks, generally a `•` */
323
+ compoundWord?: string | undefined;
295
324
  }
296
325
  interface Progress {
297
- type: 'progress';
298
- /** Number of Completed Tasks so far */
299
- completed: number;
300
- /**
301
- * Number of tasks remaining, this number is allowed to increase over time since
302
- * completed tasks can generate new tasks.
303
- */
304
- remaining: number;
326
+ type: "progress";
327
+ /** Number of Completed Tasks so far */
328
+ completed: number;
329
+ /**
330
+ * Number of tasks remaining, this number is allowed to increase over time since
331
+ * completed tasks can generate new tasks.
332
+ */
333
+ remaining: number;
305
334
  }
306
335
  type GenerateNextParam = MaxCost | symbol | undefined;
307
336
  type GenerateSuggestionResult = SuggestionResultBase | Progress | undefined;
308
337
  /**
309
- * Ask for the next result.
310
- * maxCost - sets the max cost for following suggestions
311
- * This is used to limit which suggestions are emitted.
312
- * If the `iterator.next()` returns `undefined`, it is to request a value for maxCost.
313
- *
314
- * The SuggestionIterator is generally the
315
- */
338
+ * Ask for the next result.
339
+ * maxCost - sets the max cost for following suggestions
340
+ * This is used to limit which suggestions are emitted.
341
+ * If the `iterator.next()` returns `undefined`, it is to request a value for maxCost.
342
+ *
343
+ * The SuggestionIterator is generally the
344
+ */
316
345
  type SuggestionGenerator = Generator<GenerateSuggestionResult, void, GenerateNextParam>;
317
-
346
+ //#endregion
347
+ //#region src/lib/suggestions/suggestCollector.d.ts
318
348
  type FilterWordFn = (word: string, cost: number) => boolean;
319
349
  interface SuggestionCollector {
320
- /**
321
- * Collection suggestions from a SuggestionIterator
322
- * @param src - the SuggestionIterator used to generate suggestions.
323
- * @param timeout - the amount of time in milliseconds to allow for suggestions.
324
- * before sending `symbolStopProcessing`
325
- * Iterator implementation:
326
- * @example
327
- * r = yield(suggestion);
328
- * if (r === collector.symbolStopProcessing) // ...stop generating suggestions.
329
- */
330
- collect: (src: SuggestionGenerator, timeout?: number, filter?: FilterWordFn) => void;
331
- add: (suggestion: SuggestionResultBase) => SuggestionCollector;
332
- readonly suggestions: SuggestionResult[];
333
- readonly changeLimit: number;
334
- readonly maxCost: number;
335
- readonly word: string;
336
- readonly maxNumSuggestions: number;
337
- readonly includesTies: boolean;
338
- readonly ignoreCase: boolean;
339
- readonly genSuggestionOptions: GenSuggestionOptionsRO;
340
- /**
341
- * Possible value sent to the SuggestionIterator telling it to stop processing.
342
- */
343
- readonly symbolStopProcessing: symbol;
344
- }
345
- interface SuggestionCollectorOptions extends Omit<GenSuggestionOptionsStrictRO, 'ignoreCase' | 'changeLimit'> {
346
- /**
347
- * number of best matching suggestions.
348
- * @default 10
349
- */
350
- numSuggestions: number;
351
- /**
352
- * An optional filter function that can be used to limit remove unwanted suggestions.
353
- * I.E. to remove forbidden terms.
354
- * @default () => true
355
- */
356
- filter?: FilterWordFn | undefined;
357
- /**
358
- * The number of letters that can be changed when looking for a match
359
- * @default 5
360
- */
361
- changeLimit: number | undefined;
362
- /**
363
- * Include suggestions with tied cost even if the number is greater than `numSuggestions`.
364
- * @default true
365
- */
366
- includeTies?: boolean | undefined;
367
- /**
368
- * specify if case / accents should be ignored when looking for suggestions.
369
- * @default true
370
- */
371
- ignoreCase: boolean | undefined;
372
- /**
373
- * the total amount of time to allow for suggestions.
374
- * @default 1000
375
- */
376
- timeout?: number | undefined;
377
- /**
378
- * Used to improve the sorted results.
379
- */
380
- weightMap?: WeightMap | undefined;
350
+ /**
351
+ * Collection suggestions from a SuggestionIterator
352
+ * @param src - the SuggestionIterator used to generate suggestions.
353
+ * @param timeout - the amount of time in milliseconds to allow for suggestions.
354
+ * before sending `symbolStopProcessing`
355
+ * Iterator implementation:
356
+ * @example
357
+ * r = yield(suggestion);
358
+ * if (r === collector.symbolStopProcessing) // ...stop generating suggestions.
359
+ */
360
+ collect: (src: SuggestionGenerator, timeout?: number, filter?: FilterWordFn) => void;
361
+ add: (suggestion: SuggestionResultBase) => SuggestionCollector;
362
+ readonly suggestions: SuggestionResult[];
363
+ readonly changeLimit: number;
364
+ readonly maxCost: number;
365
+ readonly word: string;
366
+ readonly maxNumSuggestions: number;
367
+ readonly includesTies: boolean;
368
+ readonly ignoreCase: boolean;
369
+ readonly genSuggestionOptions: GenSuggestionOptionsRO;
370
+ /**
371
+ * Possible value sent to the SuggestionIterator telling it to stop processing.
372
+ */
373
+ readonly symbolStopProcessing: symbol;
374
+ }
375
+ interface SuggestionCollectorOptions extends Omit<GenSuggestionOptionsStrictRO, "ignoreCase" | "changeLimit"> {
376
+ /**
377
+ * number of best matching suggestions.
378
+ * @default 10
379
+ */
380
+ numSuggestions: number;
381
+ /**
382
+ * An optional filter function that can be used to limit remove unwanted suggestions.
383
+ * I.E. to remove forbidden terms.
384
+ * @default () => true
385
+ */
386
+ filter?: FilterWordFn | undefined;
387
+ /**
388
+ * The number of letters that can be changed when looking for a match
389
+ * @default 5
390
+ */
391
+ changeLimit: number | undefined;
392
+ /**
393
+ * Include suggestions with tied cost even if the number is greater than `numSuggestions`.
394
+ * @default true
395
+ */
396
+ includeTies?: boolean | undefined;
397
+ /**
398
+ * specify if case / accents should be ignored when looking for suggestions.
399
+ * @default true
400
+ */
401
+ ignoreCase: boolean | undefined;
402
+ /**
403
+ * the total amount of time to allow for suggestions.
404
+ * @default 1000
405
+ */
406
+ timeout?: number | undefined;
407
+ /**
408
+ * Used to improve the sorted results.
409
+ */
410
+ weightMap?: WeightMap | undefined;
381
411
  }
382
412
  type SuggestionCollectorOptionsRO = Readonly<SuggestionCollectorOptions>;
383
413
  declare function suggestionCollector(wordToMatch: string, options: SuggestionCollectorOptionsRO): SuggestionCollector;
384
414
  /**
385
- * Impersonating a Collector, allows searching for multiple variants on the same word.
386
- * The collection is still in the original collector.
387
- * @param collector - collector to impersonate
388
- * @param word - word to present instead of `collector.word`.
389
- * @returns a SuggestionCollector
390
- */
415
+ * Impersonating a Collector, allows searching for multiple variants on the same word.
416
+ * The collection is still in the original collector.
417
+ * @param collector - collector to impersonate
418
+ * @param word - word to present instead of `collector.word`.
419
+ * @returns a SuggestionCollector
420
+ */
391
421
  declare function impersonateCollector(collector: SuggestionCollector, word: string): SuggestionCollector;
392
-
422
+ //#endregion
423
+ //#region src/lib/TrieData.d.ts
393
424
  interface TrieData extends Readonly<TrieCharacteristics> {
394
- readonly info: Readonly<TrieInfo>;
395
- /** Method used to split words into individual characters. */
396
- wordToCharacters(word: string): readonly string[];
397
- /** get an iterable for all the words in the dictionary. */
398
- words(): Iterable<string>;
399
- getRoot(): ITrieNodeRoot;
400
- getNode(prefix: string): ITrieNode | undefined;
401
- has(word: string): boolean;
402
- isForbiddenWord(word: string): boolean;
403
- readonly hasForbiddenWords: boolean;
404
- readonly hasCompoundWords: boolean;
405
- readonly hasNonStrictWords: boolean;
406
- readonly size: number;
407
- }
408
-
425
+ readonly info: Readonly<TrieInfo>;
426
+ /** Method used to split words into individual characters. */
427
+ wordToCharacters(word: string): readonly string[];
428
+ /** get an iterable for all the words in the dictionary. */
429
+ words(): Iterable<string>;
430
+ getRoot(): ITrieNodeRoot;
431
+ getNode(prefix: string): ITrieNode | undefined;
432
+ has(word: string): boolean;
433
+ isForbiddenWord(word: string): boolean;
434
+ readonly hasForbiddenWords: boolean;
435
+ readonly hasCompoundWords: boolean;
436
+ readonly hasNonStrictWords: boolean;
437
+ readonly size: number;
438
+ }
439
+ //#endregion
440
+ //#region src/lib/ITrie.d.ts
409
441
  interface ITrie {
410
- readonly data: TrieData;
411
- /**
412
- * Approximate number of words in the Trie, the first call to this method might be expensive.
413
- * Use `size` to get the number of nodes.
414
- *
415
- * It does NOT count natural compound words. Natural compounds are words that are composed of appending
416
- * multiple words to make a new word. This is common in languages like German and Dutch.
417
- */
418
- numWords(): number;
419
- /**
420
- * Used to check if the number of words has been calculated.
421
- */
422
- isNumWordsKnown(): boolean;
423
- /**
424
- * The number of nodes in the Trie. There is a rough corelation between the size and the number of words.
425
- */
426
- readonly size: number;
427
- readonly info: Readonly<TrieInfo>;
428
- /**
429
- * @param text - text to find in the Trie
430
- */
431
- find(text: string): ITrieNode | undefined;
432
- has(word: string): boolean;
433
- has(word: string, minLegacyCompoundLength: boolean | number): boolean;
434
- /**
435
- * Determine if a word is in the dictionary.
436
- * @param word - the exact word to search for - must be normalized.
437
- * @param caseSensitive - false means also searching a dictionary where the words were normalized to lower case and accents removed.
438
- * @returns true if the word was found and is not forbidden.
439
- */
440
- hasWord(word: string, caseSensitive: boolean): boolean;
441
- findWord(word: string, options?: FindWordOptions): FindFullResult$1;
442
- /**
443
- * Determine if a word is in the forbidden word list.
444
- * @param word the word to lookup.
445
- */
446
- isForbiddenWord(word: string): boolean;
447
- /**
448
- * Provides an ordered sequence of words with the prefix of text.
449
- */
450
- completeWord(text: string): Iterable<string>;
451
- /**
452
- * Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
453
- * @param text - the text to search for
454
- * @param options - Controls the generated suggestions:
455
- * - ignoreCase - Ignore Case and Accents
456
- * - numSuggestions - the maximum number of suggestions to return.
457
- * - compoundMethod - Use to control splitting words.
458
- * - changeLimit - the maximum number of changes allowed to text. This is an approximate value, since some changes cost less than others.
459
- * the lower the value, the faster results are returned. Values less than 4 are best.
460
- */
461
- suggest(text: string, options: SuggestionOptions): string[];
462
- /**
463
- * Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
464
- * The results include the word and adjusted edit cost. This is useful for merging results from multiple tries.
465
- */
466
- suggestWithCost(text: string, options: SuggestionOptions): SuggestionResult[];
467
- /**
468
- * genSuggestions will generate suggestions and send them to `collector`. `collector` is responsible for returning the max acceptable cost.
469
- * Costs are measured in weighted changes. A cost of 100 is the same as 1 edit. Some edits are considered cheaper.
470
- * Returning a MaxCost < 0 will effectively cause the search for suggestions to stop.
471
- */
472
- genSuggestions(collector: SuggestionCollector, compoundMethod?: CompoundWordsMethod): void;
473
- /**
474
- * Returns an iterator that can be used to get all words in the trie. For some dictionaries, this can result in millions of words.
475
- */
476
- words(): Iterable<string>;
477
- /**
478
- * Allows iteration over the entire tree.
479
- * On the returned Iterator, calling .next(goDeeper: boolean), allows for controlling the depth.
480
- */
481
- iterate(): WalkerIterator;
482
- readonly weightMap: WeightMap | undefined;
483
- readonly isCaseAware: boolean;
484
- readonly hasForbiddenWords: boolean;
485
- readonly hasCompoundWords: boolean;
486
- readonly hasNonStrictWords: boolean;
442
+ readonly data: TrieData;
443
+ /**
444
+ * Approximate number of words in the Trie, the first call to this method might be expensive.
445
+ * Use `size` to get the number of nodes.
446
+ *
447
+ * It does NOT count natural compound words. Natural compounds are words that are composed of appending
448
+ * multiple words to make a new word. This is common in languages like German and Dutch.
449
+ */
450
+ numWords(): number;
451
+ /**
452
+ * Used to check if the number of words has been calculated.
453
+ */
454
+ isNumWordsKnown(): boolean;
455
+ /**
456
+ * The number of nodes in the Trie. There is a rough corelation between the size and the number of words.
457
+ */
458
+ readonly size: number;
459
+ readonly info: Readonly<TrieInfo>;
460
+ /**
461
+ * @param text - text to find in the Trie
462
+ */
463
+ find(text: string): ITrieNode | undefined;
464
+ has(word: string): boolean;
465
+ has(word: string, minLegacyCompoundLength: boolean | number): boolean;
466
+ /**
467
+ * Determine if a word is in the dictionary.
468
+ * @param word - the exact word to search for - must be normalized.
469
+ * @param caseSensitive - false means also searching a dictionary where the words were normalized to lower case and accents removed.
470
+ * @returns true if the word was found and is not forbidden.
471
+ */
472
+ hasWord(word: string, caseSensitive: boolean): boolean;
473
+ findWord(word: string, options?: FindWordOptions): FindFullResult$1;
474
+ /**
475
+ * Determine if a word is in the forbidden word list.
476
+ * @param word the word to lookup.
477
+ */
478
+ isForbiddenWord(word: string): boolean;
479
+ /**
480
+ * Provides an ordered sequence of words with the prefix of text.
481
+ */
482
+ completeWord(text: string): Iterable<string>;
483
+ /**
484
+ * Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
485
+ * @param text - the text to search for
486
+ * @param options - Controls the generated suggestions:
487
+ * - ignoreCase - Ignore Case and Accents
488
+ * - numSuggestions - the maximum number of suggestions to return.
489
+ * - compoundMethod - Use to control splitting words.
490
+ * - changeLimit - the maximum number of changes allowed to text. This is an approximate value, since some changes cost less than others.
491
+ * the lower the value, the faster results are returned. Values less than 4 are best.
492
+ */
493
+ suggest(text: string, options: SuggestionOptions): string[];
494
+ /**
495
+ * Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
496
+ * The results include the word and adjusted edit cost. This is useful for merging results from multiple tries.
497
+ */
498
+ suggestWithCost(text: string, options: SuggestionOptions): SuggestionResult[];
499
+ /**
500
+ * genSuggestions will generate suggestions and send them to `collector`. `collector` is responsible for returning the max acceptable cost.
501
+ * Costs are measured in weighted changes. A cost of 100 is the same as 1 edit. Some edits are considered cheaper.
502
+ * Returning a MaxCost < 0 will effectively cause the search for suggestions to stop.
503
+ */
504
+ genSuggestions(collector: SuggestionCollector, compoundMethod?: CompoundWordsMethod): void;
505
+ /**
506
+ * Returns an iterator that can be used to get all words in the trie. For some dictionaries, this can result in millions of words.
507
+ */
508
+ words(): Iterable<string>;
509
+ /**
510
+ * Allows iteration over the entire tree.
511
+ * On the returned Iterator, calling .next(goDeeper: boolean), allows for controlling the depth.
512
+ */
513
+ iterate(): WalkerIterator$1;
514
+ readonly weightMap: WeightMap | undefined;
515
+ readonly isCaseAware: boolean;
516
+ readonly hasForbiddenWords: boolean;
517
+ readonly hasCompoundWords: boolean;
518
+ readonly hasNonStrictWords: boolean;
487
519
  }
488
520
  interface FindWordOptions {
489
- caseSensitive?: boolean;
490
- useLegacyWordCompounds?: boolean | number;
491
- checkForbidden?: boolean;
521
+ caseSensitive?: boolean;
522
+ useLegacyWordCompounds?: boolean | number;
523
+ checkForbidden?: boolean;
492
524
  }
493
525
  type FindWordOptionsRO = Readonly<FindWordOptions>;
494
-
526
+ //#endregion
527
+ //#region src/lib/buildITrie.d.ts
495
528
  declare function buildITrieFromWords(words: Iterable<string>, info?: PartialTrieInfo): ITrie;
496
-
529
+ //#endregion
530
+ //#region src/lib/consolidate.d.ts
497
531
  /**
498
- * Consolidate to DAWG
499
- * @param root the root of the Trie tree
500
- */
532
+ * Consolidate to DAWG
533
+ * @param root the root of the Trie tree
534
+ */
501
535
  declare function consolidate(root: TrieRoot): TrieRoot;
502
-
536
+ //#endregion
537
+ //#region src/lib/constants.d.ts
503
538
  declare const COMPOUND_FIX = "+";
504
539
  declare const OPTIONAL_COMPOUND_FIX = "*";
505
540
  declare const CASE_INSENSITIVE_PREFIX = "~";
506
541
  declare const FORBID_PREFIX = "!";
507
542
  declare const defaultTrieInfo: TrieInfo;
508
-
543
+ //#endregion
544
+ //#region src/lib/decodeTrie.d.ts
509
545
  declare function decodeTrie(raw: string | Buffer): ITrie;
510
-
546
+ //#endregion
547
+ //#region src/lib/io/importExport.d.ts
511
548
  interface ExportOptions {
512
- base?: number;
513
- comment?: string;
514
- version?: number;
515
- addLineBreaksToImproveDiffs?: boolean;
549
+ base?: number;
550
+ comment?: string;
551
+ version?: number;
552
+ addLineBreaksToImproveDiffs?: boolean;
516
553
  }
517
554
  /**
518
- * Serialize a TrieNode.
519
- * Note: This is destructive. The node will no longer be usable.
520
- * Even though it is possible to preserve the trie, dealing with very large tries can consume a lot of memory.
521
- * Considering this is the last step before exporting, it was decided to let this be destructive.
522
- */
555
+ * Serialize a TrieNode.
556
+ * Note: This is destructive. The node will no longer be usable.
557
+ * Even though it is possible to preserve the trie, dealing with very large tries can consume a lot of memory.
558
+ * Considering this is the last step before exporting, it was decided to let this be destructive.
559
+ */
523
560
  declare function serializeTrie(root: TrieRoot, options?: ExportOptions | number): Iterable<string>;
524
561
  declare function importTrie(input: Iterable<string> | IterableIterator<string> | string[] | string): TrieRoot;
525
-
526
- type DictionaryInformation = Exclude<DictionaryDefinitionAugmented['dictionaryInformation'], undefined>;
527
-
562
+ //#endregion
563
+ //#region src/lib/models/DictionaryInformation.d.ts
564
+ type DictionaryInformation = Exclude<DictionaryDefinitionAugmented["dictionaryInformation"], undefined>;
565
+ //#endregion
566
+ //#region src/lib/mappers/mapDictionaryInfoToWeightMap.d.ts
528
567
  declare function mapDictionaryInformationToWeightMap(dictInfo: DictionaryInformation): WeightMap;
529
-
568
+ //#endregion
569
+ //#region src/lib/TrieNode/find.d.ts
530
570
  interface FindResult {
531
- found: string | false;
532
- compoundUsed: boolean;
533
- caseMatched: boolean;
571
+ found: string | false;
572
+ compoundUsed: boolean;
573
+ caseMatched: boolean;
534
574
  }
535
575
  interface FindFullResult extends FindResult {
536
- /**
537
- * Is the word explicitly forbidden.
538
- * - `true` - word is in the forbidden list.
539
- * - `false` - word is not in the forbidden list.
540
- * - `undefined` - unknown - was not checked.
541
- * */
542
- forbidden: boolean | undefined;
543
- }
544
-
576
+ /**
577
+ * Is the word explicitly forbidden.
578
+ * - `true` - word is in the forbidden list.
579
+ * - `false` - word is not in the forbidden list.
580
+ * - `undefined` - unknown - was not checked.
581
+ * */
582
+ forbidden: boolean | undefined;
583
+ }
584
+ //#endregion
585
+ //#region src/lib/trie.d.ts
545
586
  declare class Trie {
546
- readonly root: TrieRoot;
547
- private count?;
548
- private _options;
549
- private _findOptionsDefaults;
550
- private _findOptionsExact;
551
- readonly isLegacy: boolean;
552
- private hasForbidden;
553
- constructor(root: TrieRoot, count?: number | undefined);
554
- /**
555
- * Number of words in the Trie
556
- */
557
- size(): number;
558
- isSizeKnown(): boolean;
559
- get options(): Readonly<TrieInfo>;
560
- /**
561
- * @param text - text to find in the Trie
562
- * @param minCompoundLength - deprecated - allows words to be glued together
563
- */
564
- find(text: string, minCompoundLength?: boolean | number): TrieNode | undefined;
565
- has(word: string, minLegacyCompoundLength?: boolean | number): boolean;
566
- /**
567
- * Determine if a word is in the dictionary.
568
- * @param word - the exact word to search for - must be normalized.
569
- * @param caseSensitive - false means also searching a dictionary where the words were normalized to lower case and accents removed.
570
- * @returns true if the word was found and is not forbidden.
571
- */
572
- hasWord(word: string, caseSensitive: boolean): boolean;
573
- findWord(word: string, options?: FindWordOptionsRO): FindFullResult;
574
- /**
575
- * Determine if a word is in the forbidden word list.
576
- * @param word the word to lookup.
577
- */
578
- isForbiddenWord(word: string): boolean;
579
- /**
580
- * Provides an ordered sequence of words with the prefix of text.
581
- */
582
- completeWord(text: string): Iterable<string>;
583
- /**
584
- * Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
585
- * @param text - the text to search for
586
- * @param maxNumSuggestions - the maximum number of suggestions to return.
587
- * @param compoundMethod - Use to control splitting words.
588
- * @param numChanges - the maximum number of changes allowed to text. This is an approximate value, since some changes cost less than others.
589
- * the lower the value, the faster results are returned. Values less than 4 are best.
590
- */
591
- suggest(text: string, options: SuggestionOptionsRO): string[];
592
- /**
593
- * Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
594
- * The results include the word and adjusted edit cost. This is useful for merging results from multiple tries.
595
- */
596
- suggestWithCost(text: string, options: SuggestionOptionsRO): SuggestionResult[];
597
- /**
598
- * genSuggestions will generate suggestions and send them to `collector`. `collector` is responsible for returning the max acceptable cost.
599
- * Costs are measured in weighted changes. A cost of 100 is the same as 1 edit. Some edits are considered cheaper.
600
- * Returning a MaxCost < 0 will effectively cause the search for suggestions to stop.
601
- */
602
- genSuggestions(collector: SuggestionCollector, compoundMethod?: CompoundWordsMethod): void;
603
- /**
604
- * Returns an iterator that can be used to get all words in the trie. For some dictionaries, this can result in millions of words.
605
- */
606
- words(): Iterable<string>;
607
- /**
608
- * Allows iteration over the entire tree.
609
- * On the returned Iterator, calling .next(goDeeper: boolean), allows for controlling the depth.
610
- */
611
- iterate(): WalkerIterator$1;
612
- insert(word: string): this;
613
- private calcIsLegacy;
614
- static create(words: Iterable<string> | IterableIterator<string>, options?: PartialTrieInfo): Trie;
615
- private createFindOptions;
616
- private lastCreateFindOptionsMatchCaseMap;
617
- private createFindOptionsMatchCase;
618
- }
619
-
587
+ readonly root: TrieRoot;
588
+ private count?;
589
+ private _options;
590
+ private _findOptionsDefaults;
591
+ private _findOptionsExact;
592
+ readonly isLegacy: boolean;
593
+ private hasForbidden;
594
+ constructor(root: TrieRoot, count?: number);
595
+ /**
596
+ * Number of words in the Trie
597
+ */
598
+ size(): number;
599
+ isSizeKnown(): boolean;
600
+ get options(): Readonly<TrieInfo>;
601
+ /**
602
+ * @param text - text to find in the Trie
603
+ * @param minCompoundLength - deprecated - allows words to be glued together
604
+ */
605
+ find(text: string, minCompoundLength?: boolean | number): TrieNode | undefined;
606
+ has(word: string, minLegacyCompoundLength?: boolean | number): boolean;
607
+ /**
608
+ * Determine if a word is in the dictionary.
609
+ * @param word - the exact word to search for - must be normalized.
610
+ * @param caseSensitive - false means also searching a dictionary where the words were normalized to lower case and accents removed.
611
+ * @returns true if the word was found and is not forbidden.
612
+ */
613
+ hasWord(word: string, caseSensitive: boolean): boolean;
614
+ findWord(word: string, options?: FindWordOptionsRO): FindFullResult;
615
+ /**
616
+ * Determine if a word is in the forbidden word list.
617
+ * @param word the word to lookup.
618
+ */
619
+ isForbiddenWord(word: string): boolean;
620
+ /**
621
+ * Provides an ordered sequence of words with the prefix of text.
622
+ */
623
+ completeWord(text: string): Iterable<string>;
624
+ /**
625
+ * Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
626
+ * @param text - the text to search for
627
+ * @param maxNumSuggestions - the maximum number of suggestions to return.
628
+ * @param compoundMethod - Use to control splitting words.
629
+ * @param numChanges - the maximum number of changes allowed to text. This is an approximate value, since some changes cost less than others.
630
+ * the lower the value, the faster results are returned. Values less than 4 are best.
631
+ */
632
+ suggest(text: string, options: SuggestionOptionsRO): string[];
633
+ /**
634
+ * Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
635
+ * The results include the word and adjusted edit cost. This is useful for merging results from multiple tries.
636
+ */
637
+ suggestWithCost(text: string, options: SuggestionOptionsRO): SuggestionResult[];
638
+ /**
639
+ * genSuggestions will generate suggestions and send them to `collector`. `collector` is responsible for returning the max acceptable cost.
640
+ * Costs are measured in weighted changes. A cost of 100 is the same as 1 edit. Some edits are considered cheaper.
641
+ * Returning a MaxCost < 0 will effectively cause the search for suggestions to stop.
642
+ */
643
+ genSuggestions(collector: SuggestionCollector, compoundMethod?: CompoundWordsMethod): void;
644
+ /**
645
+ * Returns an iterator that can be used to get all words in the trie. For some dictionaries, this can result in millions of words.
646
+ */
647
+ words(): Iterable<string>;
648
+ /**
649
+ * Allows iteration over the entire tree.
650
+ * On the returned Iterator, calling .next(goDeeper: boolean), allows for controlling the depth.
651
+ */
652
+ iterate(): WalkerIterator;
653
+ insert(word: string): this;
654
+ private calcIsLegacy;
655
+ static create(words: Iterable<string> | IterableIterator<string>, options?: PartialTrieInfo): Trie;
656
+ private createFindOptions;
657
+ private lastCreateFindOptionsMatchCaseMap;
658
+ private createFindOptionsMatchCase;
659
+ }
660
+ //#endregion
661
+ //#region src/lib/SimpleDictionaryParser.d.ts
620
662
  interface ParseDictionaryOptions {
621
- compoundCharacter: string;
622
- optionalCompoundCharacter: string;
623
- forbiddenPrefix: string;
624
- caseInsensitivePrefix: string;
625
- /**
626
- * Start of a single-line comment.
627
- * @default "#"
628
- */
629
- commentCharacter: string;
630
- /**
631
- * If word starts with prefix, do not strip case or accents.
632
- * @default false;
633
- */
634
- keepExactPrefix: string;
635
- /**
636
- * Tell the parser to automatically create case / accent insensitive forms.
637
- * @default true
638
- */
639
- stripCaseAndAccents: boolean;
640
- /**
641
- * Tell the parser to keep non-case/accent version in both forms.
642
- * @default false
643
- */
644
- stripCaseAndAccentsKeepDuplicate: boolean;
645
- /**
646
- * Tell the parser to keep non-case/accent version in both forms.
647
- * @default false
648
- */
649
- stripCaseAndAccentsOnForbidden: boolean;
650
- /**
651
- * Tell the parser to split into words along spaces.
652
- * @default false
653
- */
654
- split: boolean;
655
- /**
656
- * When splitting tells the parser to output both the split and non-split versions of the line.
657
- * @default false
658
- */
659
- splitKeepBoth: boolean;
660
- /**
661
- * Specify the separator for splitting words.
662
- */
663
- splitSeparator: RegExp | string;
664
- /**
665
- * Do not normalize the compound character.
666
- */
667
- keepOptionalCompoundCharacter: boolean;
663
+ compoundCharacter: string;
664
+ optionalCompoundCharacter: string;
665
+ forbiddenPrefix: string;
666
+ caseInsensitivePrefix: string;
667
+ /**
668
+ * Start of a single-line comment.
669
+ * @default "#"
670
+ */
671
+ commentCharacter: string;
672
+ /**
673
+ * If word starts with prefix, do not strip case or accents.
674
+ * @default false;
675
+ */
676
+ keepExactPrefix: string;
677
+ /**
678
+ * Tell the parser to automatically create case / accent insensitive forms.
679
+ * @default true
680
+ */
681
+ stripCaseAndAccents: boolean;
682
+ /**
683
+ * Tell the parser to keep non-case/accent version in both forms.
684
+ * @default false
685
+ */
686
+ stripCaseAndAccentsKeepDuplicate: boolean;
687
+ /**
688
+ * Tell the parser to keep non-case/accent version in both forms.
689
+ * @default false
690
+ */
691
+ stripCaseAndAccentsOnForbidden: boolean;
692
+ /**
693
+ * Tell the parser to split into words along spaces.
694
+ * @default false
695
+ */
696
+ split: boolean;
697
+ /**
698
+ * When splitting tells the parser to output both the split and non-split versions of the line.
699
+ * @default false
700
+ */
701
+ splitKeepBoth: boolean;
702
+ /**
703
+ * Specify the separator for splitting words.
704
+ */
705
+ splitSeparator: RegExp | string;
706
+ /**
707
+ * Do not normalize the compound character.
708
+ */
709
+ keepOptionalCompoundCharacter: boolean;
668
710
  }
669
711
  /**
670
- * Normalizes a dictionary words based upon prefix / suffixes.
671
- * Case insensitive versions are also generated.
672
- * @param options - defines prefixes used when parsing lines.
673
- * @returns words that have been normalized.
674
- */
712
+ * Normalizes a dictionary words based upon prefix / suffixes.
713
+ * Case insensitive versions are also generated.
714
+ * @param options - defines prefixes used when parsing lines.
715
+ * @returns words that have been normalized.
716
+ */
675
717
  declare function createDictionaryLineParserMapper(options?: Partial<ParseDictionaryOptions>): Operator<string>;
676
718
  /**
677
- * Normalizes a dictionary words based upon prefix / suffixes.
678
- * Case insensitive versions are also generated.
679
- * @param lines - one word per line
680
- * @param _options - defines prefixes used when parsing lines.
681
- * @returns words that have been normalized.
682
- */
719
+ * Normalizes a dictionary words based upon prefix / suffixes.
720
+ * Case insensitive versions are also generated.
721
+ * @param lines - one word per line
722
+ * @param _options - defines prefixes used when parsing lines.
723
+ * @returns words that have been normalized.
724
+ */
683
725
  declare function parseDictionaryLines(lines: Iterable<string> | string, options?: Partial<ParseDictionaryOptions>): Iterable<string>;
684
726
  declare function parseDictionaryLegacy(text: string | string[], options?: Partial<ParseDictionaryOptions>): Trie;
685
727
  declare function parseDictionary(text: string | Iterable<string>, options?: Partial<ParseDictionaryOptions>): ITrie;
686
-
728
+ //#endregion
729
+ //#region src/lib/TrieBuilder.d.ts
687
730
  /**
688
- * Builds an optimized Trie from a Iterable<string>. It attempts to reduce the size of the trie
689
- * by finding common endings.
690
- * @param words Iterable set of words -- no processing is done on the words, they are inserted as is.
691
- * @param trieOptions options for the Trie
692
- */
731
+ * Builds an optimized Trie from a Iterable<string>. It attempts to reduce the size of the trie
732
+ * by finding common endings.
733
+ * @param words Iterable set of words -- no processing is done on the words, they are inserted as is.
734
+ * @param trieOptions options for the Trie
735
+ */
693
736
  declare function buildTrie(words: Iterable<string>, trieOptions?: PartialTrieOptions): Trie;
694
737
  /**
695
- * Builds a Trie from a Iterable<string>. NO attempt a reducing the size of the Trie is done.
696
- * @param words Iterable set of words -- no processing is done on the words, they are inserted as is.
697
- * @param trieOptions options for the Trie
698
- */
738
+ * Builds a Trie from a Iterable<string>. NO attempt a reducing the size of the Trie is done.
739
+ * @param words Iterable set of words -- no processing is done on the words, they are inserted as is.
740
+ * @param trieOptions options for the Trie
741
+ */
699
742
  declare function buildTrieFast(words: Iterable<string>, trieOptions?: PartialTrieOptions): Trie;
700
743
  declare class TrieBuilder {
701
- private count;
702
- private readonly signatures;
703
- private readonly cached;
704
- private readonly transforms;
705
- private _eow;
706
- /** position 0 of lastPath is always the root */
707
- private lastPath;
708
- private tails;
709
- trieOptions: TrieOptions;
710
- private numWords;
711
- private _debug_lastWordsInserted;
712
- private _debug_mode;
713
- constructor(words?: Iterable<string>, trieOptions?: PartialTrieOptions);
714
- private get _root();
715
- private signature;
716
- private _canBeCached;
717
- private tryCacheFrozen;
718
- private freeze;
719
- private tryToCache;
720
- private storeTransform;
721
- private addChild;
722
- private buildTail;
723
- private _insert;
724
- insertWord(word: string): void;
725
- insert(words: Iterable<string>): void;
726
- /**
727
- * Resets the builder
728
- */
729
- reset(): void;
730
- build(consolidateSuffixes?: boolean): Trie;
731
- private debugStack;
732
- private debNodeInfo;
733
- private logDebug;
734
- private runDebug;
735
- private copyIfFrozen;
736
- private createNodeFrozen;
737
- private createNode;
738
- }
739
-
744
+ private count;
745
+ private readonly signatures;
746
+ private readonly cached;
747
+ private readonly transforms;
748
+ private _eow;
749
+ /** position 0 of lastPath is always the root */
750
+ private lastPath;
751
+ private tails;
752
+ trieOptions: TrieOptions;
753
+ private numWords;
754
+ private _debug_lastWordsInserted;
755
+ // private _debug_mode = true;
756
+ private _debug_mode;
757
+ constructor(words?: Iterable<string>, trieOptions?: PartialTrieOptions);
758
+ private get _root();
759
+ private signature;
760
+ private _canBeCached;
761
+ private tryCacheFrozen;
762
+ private freeze;
763
+ private tryToCache;
764
+ private storeTransform;
765
+ private addChild;
766
+ private buildTail;
767
+ private _insert;
768
+ insertWord(word: string): void;
769
+ insert(words: Iterable<string>): void;
770
+ /**
771
+ * Resets the builder
772
+ */
773
+ reset(): void;
774
+ build(consolidateSuffixes?: boolean): Trie;
775
+ private debugStack;
776
+ private debNodeInfo;
777
+ private logDebug;
778
+ private runDebug;
779
+ private copyIfFrozen;
780
+ private createNodeFrozen;
781
+ private createNode;
782
+ }
783
+ //#endregion
784
+ //#region src/lib/TrieNode/trie-util.d.ts
740
785
  declare function insert(word: string, root?: TrieNode): TrieNode;
741
786
  declare function isWordTerminationNode(node: TrieNode): boolean;
742
787
  /**
743
- * Sorts the nodes in a trie in place.
744
- */
788
+ * Sorts the nodes in a trie in place.
789
+ */
745
790
  declare function orderTrie(node: TrieNode): void;
746
791
  /**
747
- * Generator an iterator that will walk the Trie parent then children in a depth first fashion that preserves sorted order.
748
- */
749
- declare function walk(node: TrieNode): Iterable<YieldResult$1>;
792
+ * Generator an iterator that will walk the Trie parent then children in a depth first fashion that preserves sorted order.
793
+ */
794
+ declare function walk(node: TrieNode): Iterable<YieldResult>;
750
795
  declare const iterateTrie: typeof walk;
751
796
  /**
752
- * Generate a Iterator that can walk a Trie and yield the words.
753
- */
797
+ * Generate a Iterator that can walk a Trie and yield the words.
798
+ */
754
799
  declare function iteratorTrieWords(node: TrieNode): Iterable<string>;
755
800
  declare function createTrieRoot(options: PartialTrieInfo): TrieRoot;
756
801
  declare function createTrieRootFromList(words: Iterable<string>, options?: PartialTrieInfo): TrieRoot;
@@ -760,54 +805,69 @@ declare function countNodes(root: TrieNode): number;
760
805
  declare function countWords(root: TrieNode): number;
761
806
  declare function isCircular(root: TrieNode): boolean;
762
807
  declare function trieNodeToRoot(node: TrieNode, options: PartialTrieInfo): TrieRoot;
763
-
808
+ //#endregion
809
+ //#region src/lib/utils/isDefined.d.ts
764
810
  declare function isDefined<T>(t: T | undefined): t is T;
765
-
811
+ //#endregion
812
+ //#region src/lib/utils/mergeDefaults.d.ts
766
813
  /**
767
- * Creates a new object of type T based upon the field values from `value`.
768
- * n[k] = value[k] ?? default[k] where k must be a field in default.
769
- * Note: it will remove fields not in defaultValue!
770
- * @param value
771
- * @param defaultValue
772
- */
814
+ * Creates a new object of type T based upon the field values from `value`.
815
+ * n[k] = value[k] ?? default[k] where k must be a field in default.
816
+ * Note: it will remove fields not in defaultValue!
817
+ * @param value
818
+ * @param defaultValue
819
+ */
773
820
  declare function mergeDefaults<T extends object>(value: Readonly<PartialWithUndefined<T>> | undefined, defaultValue: T): T;
774
-
821
+ //#endregion
822
+ //#region src/lib/utils/mergeOptionalWithDefaults.d.ts
775
823
  type ROPartialTrieOptions = Readonly<PartialTrieInfo>;
776
824
  declare function mergeOptionalWithDefaults(options: ROPartialTrieOptions): TrieInfo;
777
825
  declare function mergeOptionalWithDefaults(options: ROPartialTrieOptions, ...moreOptions: ROPartialTrieOptions[]): TrieInfo;
778
-
826
+ //#endregion
827
+ //#region src/lib/utils/normalizeWord.d.ts
779
828
  /**
780
- * Normalize word unicode.
781
- * @param text - text to normalize
782
- * @returns returns a word normalized to `NFC`
783
- */
829
+ * Normalize word unicode.
830
+ * @param text - text to normalize
831
+ * @returns returns a word normalized to `NFC`
832
+ */
784
833
  declare const normalizeWord: (text: string) => string;
785
834
  /**
786
- * converts text to lower case and removes any accents.
787
- * @param text - text to convert
788
- * @returns lowercase word without accents
789
- * @deprecated true
790
- */
835
+ * converts text to lower case and removes any accents.
836
+ * @param text - text to convert
837
+ * @returns lowercase word without accents
838
+ * @deprecated true
839
+ */
791
840
  declare const normalizeWordToLowercase: (text: string) => string;
792
841
  /**
793
- * generate case insensitive forms of a word
794
- * @param text - text to convert
795
- * @returns the forms of the word.
796
- */
842
+ * generate case insensitive forms of a word
843
+ * @param text - text to convert
844
+ * @returns the forms of the word.
845
+ */
797
846
  declare const normalizeWordForCaseInsensitive: (text: string) => string[];
798
-
847
+ //#endregion
848
+ //#region src/lib/utils/text.d.ts
799
849
  /**
800
- * Expand a line into a set of characters.
801
- *
802
- * Example:
803
- * - `a-c` -> `<a,b,c>`
804
- * - `ac-` -> `<a,c,->`
805
- * - `-abz` -> `<-,a,b,z>`
806
- * - `\u0300-\u0308` -> `<accents>`
807
- *
808
- * @param line - set of characters
809
- * @param rangeChar - the character to indicate ranges, set to empty to not have ranges.
810
- */
850
+ * Expand a line into a set of characters.
851
+ *
852
+ * Example:
853
+ * - `a-c` -> `<a,b,c>`
854
+ * - `ac-` -> `<a,c,->`
855
+ * - `-abz` -> `<-,a,b,z>`
856
+ * - `\u0300-\u0308` -> `<accents>`
857
+ *
858
+ * @param line - set of characters
859
+ * @param rangeChar - the character to indicate ranges, set to empty to not have ranges.
860
+ */
811
861
  declare function expandCharacterSet(line: string, rangeChar?: string): Set<string>;
812
-
813
- export { CASE_INSENSITIVE_PREFIX, COMPOUND_FIX, type ChildMap, CompoundWordsMethod, type ExportOptions, FLAG_WORD, FORBID_PREFIX, type FindFullResult, type FindWordOptions, type HintedWalkerIterator, type Hinting, type ITrie, JOIN_SEPARATOR, type MaxCost, OPTIONAL_COMPOUND_FIX, type PartialTrieOptions, type SuggestionCollector, type SuggestionResult, Trie, TrieBuilder, type TrieNode, type TrieOptions, type TrieOptionsRO, type TrieRoot, WORD_SEPARATOR, type WalkerIterator$1 as WalkerIterator, type WeightMap, type YieldResult$1 as YieldResult, buildITrieFromWords, buildTrie, buildTrieFast, consolidate, countNodes, countWords, createDictionaryLineParserMapper as createDictionaryLineParser, createTrieRoot, createTrieRootFromList, createWeightedMap, decodeTrie, defaultTrieInfo, defaultTrieInfo as defaultTrieOptions, editDistance, editDistanceWeighted, expandCharacterSet, findNode, has, hintedWalker, impersonateCollector, importTrie, insert, isCircular, isDefined, isWordTerminationNode, iterateTrie, iteratorTrieWords, mapDictionaryInformationToWeightMap, mergeDefaults, mergeOptionalWithDefaults, normalizeWord, normalizeWordForCaseInsensitive, normalizeWordToLowercase, orderTrie, parseDictionary, parseDictionaryLegacy, parseDictionaryLines, serializeTrie, suggestionCollector, trieNodeToRoot, walk, walker };
862
+ /**
863
+ * Expands a range between two characters.
864
+ * - `a <= b` -- `[a, b]`
865
+ * - `a > b` -- `[]`
866
+ * @param a - staring character
867
+ * @param b - ending character
868
+ * @returns array of unicode characters.
869
+ */
870
+
871
+ //#endregion
872
+ export { CASE_INSENSITIVE_PREFIX, COMPOUND_FIX, ChildMap, CompoundWordsMethod, ExportOptions, FLAG_WORD, FORBID_PREFIX, FindFullResult, FindWordOptions, HintedWalkerIterator, Hinting, ITrie, JOIN_SEPARATOR, MaxCost, OPTIONAL_COMPOUND_FIX, PartialTrieOptions, SuggestionCollector, SuggestionCostMapDef, SuggestionResult, Trie, TrieBuilder, TrieNode, TrieOptions, TrieOptionsRO, TrieRoot, WORD_SEPARATOR, WalkerIterator, WeightMap, YieldResult, buildITrieFromWords, buildTrie, buildTrieFast, consolidate, countNodes, countWords, createDictionaryLineParserMapper as createDictionaryLineParser, createTrieRoot, createTrieRootFromList, createWeightedMap, decodeTrie, defaultTrieInfo, defaultTrieInfo as defaultTrieOptions, editDistance, editDistanceWeighted, expandCharacterSet, findNode, has, hintedWalker, impersonateCollector, importTrie, insert, isCircular, isDefined, isWordTerminationNode, iterateTrie, iteratorTrieWords, mapDictionaryInformationToWeightMap, mergeDefaults, mergeOptionalWithDefaults, normalizeWord, normalizeWordForCaseInsensitive, normalizeWordToLowercase, orderTrie, parseDictionary, parseDictionaryLegacy, parseDictionaryLines, serializeTrie, suggestionCollector, trieNodeToRoot, walk, walker };
873
+ //# sourceMappingURL=index.d.ts.map