cspell-trie-lib 6.14.1 → 6.14.3

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.
@@ -65,4 +65,9 @@ export declare function createDictionaryLineParserMapper(options?: Partial<Parse
65
65
  export declare function parseDictionaryLines(lines: Iterable<string> | string, options?: Partial<ParseDictionaryOptions>): Iterable<string>;
66
66
  export declare function parseLinesToDictionary(lines: Iterable<string>, options?: Partial<ParseDictionaryOptions>): Trie;
67
67
  export declare function parseDictionary(text: string, options?: Partial<ParseDictionaryOptions>): Trie;
68
+ declare function splitLine(line: string, regExp: RegExp | string): string[];
69
+ export declare const __testing__: {
70
+ splitLine: typeof splitLine;
71
+ };
72
+ export {};
68
73
  //# sourceMappingURL=SimpleDictionaryParser.d.ts.map
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseDictionary = exports.parseLinesToDictionary = exports.parseDictionaryLines = exports.createDictionaryLineParserMapper = exports.setOfCSpellDirectiveFlags = exports.cSpellToolDirective = exports.defaultParseDictionaryOptions = void 0;
3
+ exports.__testing__ = exports.parseDictionary = exports.parseLinesToDictionary = exports.parseDictionaryLines = exports.createDictionaryLineParserMapper = exports.setOfCSpellDirectiveFlags = exports.cSpellToolDirective = exports.defaultParseDictionaryOptions = void 0;
4
4
  const sync_1 = require("@cspell/cspell-pipe/sync");
5
5
  const constants_1 = require("./constants");
6
6
  const trie_util_1 = require("./trie-util");
7
7
  const TrieBuilder_1 = require("./TrieBuilder");
8
- const RegExpSplit = /(?<!\\)[\s,;]/g;
8
+ const RegExpSplit = /[\s,;]/g;
9
9
  const _defaultOptions = {
10
10
  commentCharacter: constants_1.LINE_COMMENT,
11
11
  optionalCompoundCharacter: constants_1.OPTIONAL_COMPOUND_FIX,
@@ -126,8 +126,8 @@ function createDictionaryLineParserMapper(options) {
126
126
  const lineEscaped = line.indexOf('"') >= 0
127
127
  ? line.replace(/".*?"/g, (quoted) => ' ' + quoted.replace(/(\s)/g, '\\$1') + ' ')
128
128
  : line;
129
- const words = lineEscaped.split(splitSeparator);
130
- yield* words.map((escaped) => escaped.replace(/\\(\s)/g, '$1'));
129
+ const words = splitLine(lineEscaped, splitSeparator);
130
+ yield* words.map((escaped) => escaped.replace(/\\/g, ''));
131
131
  if (!splitKeepBoth)
132
132
  continue;
133
133
  }
@@ -180,4 +180,20 @@ function mergeOptions(base, ...partials) {
180
180
  }
181
181
  return opt;
182
182
  }
183
+ const RegExpToEncode = /\\([\s,;])/g;
184
+ const RegExpDecode = /<<(%[\da-f]{2})>>/gi;
185
+ function encodeLine(line) {
186
+ return line.replace(RegExpToEncode, (_, v) => '<<' + encodeURIComponent(v) + '>>');
187
+ }
188
+ function decodeLine(line) {
189
+ return line.replace(RegExpDecode, (_, v) => '\\' + decodeURIComponent(v));
190
+ }
191
+ function splitLine(line, regExp) {
192
+ return encodeLine(line)
193
+ .split(regExp)
194
+ .map((line) => decodeLine(line));
195
+ }
196
+ exports.__testing__ = {
197
+ splitLine,
198
+ };
183
199
  //# sourceMappingURL=SimpleDictionaryParser.js.map
@@ -11,7 +11,7 @@ export interface TrieOptions {
11
11
  stripCaseAndAccentsPrefix: string;
12
12
  forbiddenWordPrefix: string;
13
13
  }
14
- export declare type PartialTrieOptions = PartialWithUndefined<TrieOptions> | undefined;
14
+ export type PartialTrieOptions = PartialWithUndefined<TrieOptions> | undefined;
15
15
  export interface TrieRoot extends TrieOptions {
16
16
  c: ChildMap;
17
17
  }
@@ -9,7 +9,7 @@ export interface WalkItem {
9
9
  /** true iff compound edge */
10
10
  c: boolean;
11
11
  }
12
- export declare type WalkNext = boolean;
12
+ export type WalkNext = boolean;
13
13
  /**
14
14
  *
15
15
  * Depth first walk of a compound trie.
@@ -1,5 +1,5 @@
1
1
  import { SuggestionCostMapDef } from '../models/suggestionCostsDef';
2
- export declare type WeightedRepMapTrie = Record<string, WeightedRepTrieNode>;
2
+ export type WeightedRepMapTrie = Record<string, WeightedRepTrieNode>;
3
3
  interface WeightedRepTrieNode {
4
4
  /** The nested Trie nodes */
5
5
  r?: WeightedRepMapTrie | undefined;
@@ -1,20 +1,20 @@
1
1
  import { TrieNode, TrieRoot } from './TrieNode';
2
2
  import type { PartialWithUndefined } from './types';
3
- declare type Root = PartialWithUndefined<TrieRoot>;
3
+ type Root = PartialWithUndefined<TrieRoot>;
4
4
  /**
5
5
  * No compounding allowed.
6
6
  */
7
- export declare type CompoundModeNone = 'none';
7
+ export type CompoundModeNone = 'none';
8
8
  /**
9
9
  * Allow natural compounding in the dictionary
10
10
  * using compound prefixes
11
11
  */
12
- export declare type CompoundModesCompound = 'compound';
12
+ export type CompoundModesCompound = 'compound';
13
13
  /**
14
14
  * Allow all possible compounds -- Very slow.
15
15
  */
16
- export declare type CompoundModesLegacy = 'legacy';
17
- export declare type CompoundModes = CompoundModeNone | CompoundModesCompound | CompoundModesLegacy;
16
+ export type CompoundModesLegacy = 'legacy';
17
+ export type CompoundModes = CompoundModeNone | CompoundModesCompound | CompoundModesLegacy;
18
18
  export interface FindOptions {
19
19
  matchCase: boolean;
20
20
  compoundMode: CompoundModes;
@@ -23,7 +23,7 @@ export interface FindOptions {
23
23
  caseInsensitivePrefix: string;
24
24
  legacyMinCompoundLength: number;
25
25
  }
26
- export declare type PartialFindOptions = PartialWithUndefined<FindOptions> | undefined;
26
+ export type PartialFindOptions = PartialWithUndefined<FindOptions> | undefined;
27
27
  export interface FindNodeResult {
28
28
  node: TrieNode | undefined;
29
29
  }
@@ -141,7 +141,7 @@ function* toIterableIterator(iter) {
141
141
  yield* iter;
142
142
  }
143
143
  function importTrie(linesX) {
144
- linesX = typeof linesX === 'string' ? linesX.split(/(?<=\n)/) : linesX;
144
+ linesX = typeof linesX === 'string' ? linesX.split(/^/m) : linesX;
145
145
  const root = (0, trie_util_1.trieNodeToRoot)({}, {});
146
146
  let radix = 16;
147
147
  const comment = /^\s*#/;
@@ -212,10 +212,10 @@ function buildReferenceMap(root, base) {
212
212
  return { refCounts: refs };
213
213
  }
214
214
  function importTrie(linesX) {
215
- linesX = typeof linesX === 'string' ? linesX.split(/(?<=\n)/) : linesX;
215
+ linesX = typeof linesX === 'string' ? linesX.split(/^/m) : linesX;
216
216
  let radix = 10;
217
217
  const comment = /^\s*#/;
218
- const iter = tapIterable((0, sync_1.pipe)(linesX, (0, sync_1.opConcatMap)((a) => a.split(/(?<=\n)(?!$)/))));
218
+ const iter = tapIterable((0, sync_1.pipe)(linesX, (0, sync_1.opConcatMap)((a) => a.split(/^/m))));
219
219
  function parseHeaderRows(headerRows) {
220
220
  const header = headerRows.slice(0, 2).join('\n');
221
221
  const headerReg = /^TrieXv[34]\nbase=(\d+)$/;
@@ -374,7 +374,10 @@ function parseStream(radix, iter) {
374
374
  function parser(acc, s) {
375
375
  json = json + s;
376
376
  if (s === REF_INDEX_END) {
377
- refIndex = JSON.parse(json);
377
+ refIndex = json
378
+ .replace(/[\s[\]]/g, '')
379
+ .split(',')
380
+ .map((n) => parseInt(n, radix));
378
381
  return { ...acc, parser: undefined };
379
382
  }
380
383
  return acc;
@@ -1,6 +1,6 @@
1
1
  import { HunspellCosts, EditCosts } from '../models/DictionaryInformation';
2
- export declare type EditCostsRequired = Required<EditCosts>;
3
- export declare type HunspellCostsRequired = Required<HunspellCosts>;
2
+ export type EditCostsRequired = Required<EditCosts>;
3
+ export type HunspellCostsRequired = Required<HunspellCosts>;
4
4
  export declare function mapHunspellCosts(costs?: HunspellCosts): HunspellCostsRequired;
5
5
  export declare function mapEditCosts(costs?: EditCosts): EditCostsRequired;
6
6
  //# sourceMappingURL=mapCosts.d.ts.map
@@ -1,8 +1,8 @@
1
1
  import type { DictionaryDefinitionAugmented } from '@cspell/cspell-types';
2
2
  export type { CharacterSet, CharacterSetCosts, EditCosts } from '@cspell/cspell-types';
3
- export declare type DictionaryInformation = Exclude<DictionaryDefinitionAugmented['dictionaryInformation'], undefined>;
4
- export declare type SuggestionEditCosts = Exclude<DictionaryInformation['suggestionEditCosts'], undefined>;
5
- export declare type HunspellInformation = Exclude<DictionaryInformation['hunspellInformation'], undefined>;
6
- export declare type HunspellCosts = Exclude<HunspellInformation['costs'], undefined>;
7
- export declare type HunspellAff = HunspellInformation['aff'];
3
+ export type DictionaryInformation = Exclude<DictionaryDefinitionAugmented['dictionaryInformation'], undefined>;
4
+ export type SuggestionEditCosts = Exclude<DictionaryInformation['suggestionEditCosts'], undefined>;
5
+ export type HunspellInformation = Exclude<DictionaryInformation['hunspellInformation'], undefined>;
6
+ export type HunspellCosts = Exclude<HunspellInformation['costs'], undefined>;
7
+ export type HunspellAff = HunspellInformation['aff'];
8
8
  //# sourceMappingURL=DictionaryInformation.d.ts.map
@@ -1,3 +1,3 @@
1
- export declare type Entry = [string, string] | [string, string, string];
1
+ export type Entry = [string, string] | [string, string, string];
2
2
  export declare const codes: Entry[];
3
3
  //# sourceMappingURL=knownLocales.d.ts.map
@@ -21,7 +21,7 @@ export interface GenSuggestionOptionsStrict {
21
21
  */
22
22
  compoundSeparator?: string;
23
23
  }
24
- export declare type GenSuggestionOptions = Partial<GenSuggestionOptionsStrict>;
24
+ export type GenSuggestionOptions = Partial<GenSuggestionOptionsStrict>;
25
25
  export interface SuggestionOptionsStrict extends GenSuggestionOptionsStrict {
26
26
  /**
27
27
  * Maximum number of suggestions to make.
@@ -46,7 +46,7 @@ export interface SuggestionOptionsStrict extends GenSuggestionOptionsStrict {
46
46
  */
47
47
  weightMap?: WeightMap;
48
48
  }
49
- export declare type SuggestionOptions = Partial<SuggestionOptionsStrict>;
49
+ export type SuggestionOptions = Partial<SuggestionOptionsStrict>;
50
50
  export declare const defaultGenSuggestionOptions: GenSuggestionOptionsStrict;
51
51
  export declare const defaultSuggestionOptions: SuggestionOptionsStrict;
52
52
  /**
@@ -2,8 +2,8 @@ import { WeightMap } from '..';
2
2
  import { RequireOptional } from '../types';
3
3
  import { GenSuggestionOptions, GenSuggestionOptionsStrict } from './genSuggestionsOptions';
4
4
  export declare const DEFAULT_COMPOUNDED_WORD_SEPARATOR = "\u2219";
5
- export declare type Cost = number;
6
- export declare type MaxCost = Cost;
5
+ export type Cost = number;
6
+ export type MaxCost = Cost;
7
7
  export interface SuggestionResultBase {
8
8
  /** The suggested word */
9
9
  word: string;
@@ -29,8 +29,8 @@ export interface Progress {
29
29
  */
30
30
  remaining: number;
31
31
  }
32
- export declare type GenerateNextParam = MaxCost | symbol | undefined;
33
- export declare type GenerateSuggestionResult = SuggestionResultBase | Progress | undefined;
32
+ export type GenerateNextParam = MaxCost | symbol | undefined;
33
+ export type GenerateSuggestionResult = SuggestionResultBase | Progress | undefined;
34
34
  /**
35
35
  * Ask for the next result.
36
36
  * maxCost - sets the max cost for following suggestions
@@ -39,9 +39,9 @@ export declare type GenerateSuggestionResult = SuggestionResultBase | Progress |
39
39
  *
40
40
  * The SuggestionIterator is generally the
41
41
  */
42
- export declare type SuggestionGenerator = Generator<GenerateSuggestionResult, void, GenerateNextParam>;
42
+ export type SuggestionGenerator = Generator<GenerateSuggestionResult, void, GenerateNextParam>;
43
43
  export declare function compSuggestionResults(a: SuggestionResultBase, b: SuggestionResultBase): number;
44
- export declare type FilterWordFn = (word: string, cost: number) => boolean;
44
+ export type FilterWordFn = (word: string, cost: number) => boolean;
45
45
  export interface SuggestionCollector {
46
46
  /**
47
47
  * Collection suggestions from a SuggestionIterator
@@ -5,7 +5,7 @@ import { CompoundWordsMethod, YieldResult } from './walkerTypes';
5
5
  * goDeeper of true tells the walker to go deeper in the Trie if possible. Default is true.
6
6
  * This can be used to limit the walker's depth.
7
7
  */
8
- export declare type HintedWalkerIterator = Generator<YieldResult, void, Hinting | undefined>;
8
+ export type HintedWalkerIterator = Generator<YieldResult, void, Hinting | undefined>;
9
9
  export declare function hintedWalker(root: TrieRoot, ignoreCase: boolean, hint: string, compoundingMethod: CompoundWordsMethod | undefined, emitWordSeparator?: string): HintedWalkerIterator;
10
10
  /**
11
11
  * Walks the Trie and yields a value at each node.
@@ -20,5 +20,5 @@ export declare enum CompoundWordsMethod {
20
20
  */
21
21
  JOIN_WORDS = 2
22
22
  }
23
- export declare type WalkerIterator = Generator<YieldResult, void, boolean | undefined>;
23
+ export type WalkerIterator = Generator<YieldResult, void, boolean | undefined>;
24
24
  //# sourceMappingURL=walkerTypes.d.ts.map
@@ -32,7 +32,7 @@ export declare function isCircular(root: TrieNode): boolean;
32
32
  * @param value
33
33
  * @param defaultValue
34
34
  */
35
- export declare function mergeDefaults<T>(value: PartialWithUndefined<T> | undefined, defaultValue: T): T;
35
+ export declare function mergeDefaults<T extends object>(value: PartialWithUndefined<T> | undefined, defaultValue: T): T;
36
36
  export declare function trieNodeToRoot(node: TrieNode, options: PartialTrieOptions): TrieRoot;
37
37
  /**
38
38
  * Normalize word unicode.
@@ -1,4 +1,4 @@
1
- export declare type RefList = [string, number][];
1
+ export type RefList = [string, number][];
2
2
  export interface TrieRefNode {
3
3
  f?: number | undefined;
4
4
  r?: RefList | undefined;
@@ -1,70 +1,70 @@
1
1
  /**
2
2
  * Make all optional fields required.
3
3
  */
4
- export declare type RequireOptional<T> = {
4
+ export type RequireOptional<T> = {
5
5
  [K in keyof Required<T>]: T[K];
6
6
  };
7
7
  /**
8
8
  * Make all properties in T optional and Possibly undefined
9
9
  */
10
- export declare type PartialWithUndefined<T> = {
10
+ export type PartialWithUndefined<T> = {
11
11
  [P in keyof T]?: T[P] | undefined;
12
12
  };
13
13
  /**
14
14
  * Make all fields mandatory
15
15
  */
16
- export declare type Mandatory<T> = {
16
+ export type Mandatory<T> = {
17
17
  [P in keyof T]-?: Exclude<T[P], undefined>;
18
18
  };
19
19
  /**
20
20
  * Union the fields
21
21
  */
22
- export declare type UnionFields<T, U> = {
22
+ export type UnionFields<T, U> = {
23
23
  [K in keyof T | keyof U]: (K extends keyof T ? T[K] : undefined) | (K extends keyof U ? U[K] : undefined);
24
24
  };
25
25
  /**
26
26
  * The keys of an object where the values cannot be undefined.
27
27
  */
28
- export declare type RequiredKeys<T> = Exclude<{
28
+ export type RequiredKeys<T> = Exclude<{
29
29
  [P in keyof T]: T[P] extends Exclude<T[P], undefined> ? P : never;
30
30
  }[keyof T], undefined>;
31
31
  /**
32
32
  * The keys of an object where the values cannot be undefined.
33
33
  */
34
- export declare type OptionalOrUndefinedKeys<T> = Exclude<{
34
+ export type OptionalOrUndefinedKeys<T> = Exclude<{
35
35
  [P in keyof T]: T[P] extends Exclude<T[P], undefined> ? never : P;
36
36
  }[keyof T], undefined>;
37
37
  /**
38
38
  * Extract the fields that cannot be `undefined`
39
39
  */
40
- export declare type OnlyRequired<T> = {
40
+ export type OnlyRequired<T> = {
41
41
  [P in RequiredKeys<T>]: T[P];
42
42
  };
43
43
  /**
44
44
  * The keys of an object where the values cannot be undefined.
45
45
  */
46
- export declare type NoUndefined<T> = {
46
+ export type NoUndefined<T> = {
47
47
  [P in keyof T]: Exclude<T[P], undefined>;
48
48
  };
49
49
  /**
50
50
  * Extract the fields that can be `undefined`
51
51
  */
52
- export declare type OnlyOptionalOrUndefined<T> = {
52
+ export type OnlyOptionalOrUndefined<T> = {
53
53
  [P in keyof T as P extends OptionalOrUndefinedKeys<T> ? P : never]: T[P];
54
54
  };
55
55
  /**
56
56
  * Make fields that can be `undefined` optional
57
57
  */
58
- export declare type MakeOptional<T> = OnlyRequired<T> & Partial<OnlyOptionalOrUndefined<T>>;
58
+ export type MakeOptional<T> = OnlyRequired<T> & Partial<OnlyOptionalOrUndefined<T>>;
59
59
  /**
60
60
  * Like Required, but keeps the Optional.
61
61
  */
62
- export declare type RemoveUndefined<T> = {
62
+ export type RemoveUndefined<T> = {
63
63
  [P in keyof T]: Exclude<T[P], undefined>;
64
64
  };
65
65
  /**
66
66
  * Make all `undefined` optional and removes the `undefined`
67
67
  */
68
- export declare type UndefinedToOptional<T> = RemoveUndefined<MakeOptional<T>>;
69
- export declare type ArrayItem<T extends Array<unknown>> = T extends Array<infer R> ? R : never;
68
+ export type UndefinedToOptional<T> = RemoveUndefined<MakeOptional<T>>;
69
+ export type ArrayItem<T extends Array<unknown>> = T extends Array<infer R> ? R : never;
70
70
  //# sourceMappingURL=types.d.ts.map
@@ -16,7 +16,7 @@ export interface PairHeapNode<T> {
16
16
  * @param b - item b
17
17
  * @returns a number
18
18
  */
19
- export declare type CompareFn<T> = (a: T, b: T) => number;
19
+ export type CompareFn<T> = (a: T, b: T) => number;
20
20
  export declare class PairingHeap<T> implements IterableIterator<T> {
21
21
  readonly compare: CompareFn<T>;
22
22
  private _heap;
@@ -8,8 +8,8 @@ export interface Timer {
8
8
  elapsed(): number;
9
9
  }
10
10
  export declare function createTimer(hrTimeFn?: HRTimeFn): Timer;
11
- export declare type HRTimeFn = (time?: HRTime) => HRTime;
12
- export declare type HRTime = [number, number];
11
+ export type HRTimeFn = (time?: HRTime) => HRTime;
12
+ export type HRTime = [number, number];
13
13
  export declare function toMilliseconds(t: HRTime): number;
14
14
  export declare function polyHrTime(time?: HRTime): HRTime;
15
15
  //# sourceMappingURL=timer.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell-trie-lib",
3
- "version": "6.14.1",
3
+ "version": "6.14.3",
4
4
  "description": "Trie Data Structure to support cspell.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -37,8 +37,8 @@
37
37
  },
38
38
  "homepage": "https://github.com/streetsidesoftware/cspell#readme",
39
39
  "dependencies": {
40
- "@cspell/cspell-pipe": "6.14.1",
41
- "@cspell/cspell-types": "6.14.1",
40
+ "@cspell/cspell-pipe": "6.14.3",
41
+ "@cspell/cspell-types": "6.14.3",
42
42
  "fs-extra": "^10.1.0",
43
43
  "gensequence": "^4.0.2"
44
44
  },
@@ -50,8 +50,8 @@
50
50
  "@cspell/dict-es-es": "^2.2.2",
51
51
  "@types/fs-extra": "^9.0.13",
52
52
  "@types/node": "^18.11.9",
53
- "jest": "^29.2.2",
53
+ "jest": "^29.3.1",
54
54
  "rimraf": "^3.0.2"
55
55
  },
56
- "gitHead": "35db1ed216cd9aaf479429d3268482f30d824e70"
56
+ "gitHead": "df0efdbb0dc7b084579130ba5fe97441c0ab67ca"
57
57
  }