cspell-trie-lib 5.18.1 → 5.18.5
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/dist/lib/distance/distanceAStarWeighted.d.ts +2 -1
- package/dist/lib/distance/distanceAStarWeighted.js +48 -7
- package/dist/lib/distance/formatResultEx.js +3 -2
- package/dist/lib/distance/weightedMaps.d.ts +16 -2
- package/dist/lib/distance/weightedMaps.js +37 -4
- package/dist/lib/mappers/mapDictionaryInfo.d.ts +2 -0
- package/dist/lib/mappers/mapDictionaryInfo.js +15 -1
- package/dist/lib/mappers/mapDictionaryInfoToWeightMap.js +21 -1
- package/dist/lib/suggestions/suggestCollector.js +6 -5
- package/dist/lib/types.d.ts +1 -0
- package/dist/lib/utils/autoCacheMap.d.ts +11 -0
- package/dist/lib/utils/autoCacheMap.js +34 -0
- package/dist/lib/utils/memorizer.d.ts +6 -0
- package/dist/lib/utils/memorizer.js +43 -0
- package/dist/lib/utils/util.js +1 -1
- package/package.json +7 -7
|
@@ -9,6 +9,7 @@ export interface ExResult {
|
|
|
9
9
|
a: string;
|
|
10
10
|
b: string;
|
|
11
11
|
cost: number;
|
|
12
|
+
penalty: number;
|
|
12
13
|
segments: {
|
|
13
14
|
a: string;
|
|
14
15
|
b: string;
|
|
@@ -16,5 +17,5 @@ export interface ExResult {
|
|
|
16
17
|
p: number;
|
|
17
18
|
}[];
|
|
18
19
|
}
|
|
19
|
-
export declare function distanceAStarWeightedEx(wordA: string, wordB: string, map: WeightMap, cost?: number): ExResult
|
|
20
|
+
export declare function distanceAStarWeightedEx(wordA: string, wordB: string, map: WeightMap, cost?: number): ExResult;
|
|
20
21
|
//# sourceMappingURL=distanceAStarWeighted.d.ts.map
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.distanceAStarWeightedEx = exports.distanceAStarWeighted = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
4
8
|
const PairingHeap_1 = require("../utils/PairingHeap");
|
|
5
9
|
/**
|
|
6
10
|
* Calculate the edit distance between two words using an A* algorithm.
|
|
@@ -9,19 +13,20 @@ const PairingHeap_1 = require("../utils/PairingHeap");
|
|
|
9
13
|
*/
|
|
10
14
|
function distanceAStarWeighted(wordA, wordB, map, cost = 100) {
|
|
11
15
|
const best = _distanceAStarWeightedEx(wordA, wordB, map, cost);
|
|
12
|
-
|
|
16
|
+
const penalty = map.calcAdjustment(wordB);
|
|
17
|
+
return best.c + best.p + penalty;
|
|
13
18
|
}
|
|
14
19
|
exports.distanceAStarWeighted = distanceAStarWeighted;
|
|
15
20
|
function distanceAStarWeightedEx(wordA, wordB, map, cost = 100) {
|
|
16
21
|
const best = _distanceAStarWeightedEx(wordA, wordB, map, cost);
|
|
17
|
-
if (!best)
|
|
18
|
-
return undefined;
|
|
19
22
|
const aa = '^' + wordA + '$';
|
|
20
23
|
const bb = '^' + wordB + '$';
|
|
24
|
+
const penalty = map.calcAdjustment(wordB);
|
|
21
25
|
const result = {
|
|
22
26
|
a: aa,
|
|
23
27
|
b: bb,
|
|
24
|
-
cost: best.c + best.p,
|
|
28
|
+
cost: best.c + best.p + penalty,
|
|
29
|
+
penalty,
|
|
25
30
|
segments: [],
|
|
26
31
|
};
|
|
27
32
|
const segments = result.segments;
|
|
@@ -43,7 +48,7 @@ function _distanceAStarWeightedEx(wordA, wordB, map, cost = 100) {
|
|
|
43
48
|
const b = '^' + wordB + '$';
|
|
44
49
|
const aN = a.length;
|
|
45
50
|
const bN = b.length;
|
|
46
|
-
const candidates = new
|
|
51
|
+
const candidates = new CandidatePool(aN, bN);
|
|
47
52
|
candidates.add({ ai: 0, bi: 0, c: 0, p: 0, f: undefined });
|
|
48
53
|
/** Substitute / Replace */
|
|
49
54
|
function opSub(n) {
|
|
@@ -86,7 +91,7 @@ function _distanceAStarWeightedEx(wordA, wordB, map, cost = 100) {
|
|
|
86
91
|
}
|
|
87
92
|
let best;
|
|
88
93
|
// const bc2 = 2 * bc;
|
|
89
|
-
while ((best = candidates.
|
|
94
|
+
while ((best = candidates.next())) {
|
|
90
95
|
if (best.ai === aN && best.bi === bN)
|
|
91
96
|
break;
|
|
92
97
|
opSwap(best);
|
|
@@ -95,10 +100,46 @@ function _distanceAStarWeightedEx(wordA, wordB, map, cost = 100) {
|
|
|
95
100
|
opMap(best);
|
|
96
101
|
opSub(best);
|
|
97
102
|
}
|
|
103
|
+
(0, assert_1.default)(best);
|
|
98
104
|
return best;
|
|
99
105
|
}
|
|
106
|
+
class CandidatePool {
|
|
107
|
+
constructor(aN, bN) {
|
|
108
|
+
this.aN = aN;
|
|
109
|
+
this.bN = bN;
|
|
110
|
+
this.pool = new PairingHeap_1.PairingHeap(compare);
|
|
111
|
+
this.grid = [];
|
|
112
|
+
}
|
|
113
|
+
next() {
|
|
114
|
+
let n;
|
|
115
|
+
while ((n = this.pool.dequeue())) {
|
|
116
|
+
if (!n.d)
|
|
117
|
+
return n;
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
add(n) {
|
|
122
|
+
const i = idx(n.ai, n.bi, this.bN);
|
|
123
|
+
const g = this.grid[i];
|
|
124
|
+
if (!g) {
|
|
125
|
+
this.grid[i] = n;
|
|
126
|
+
this.pool.add(n);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// Do not add if the existing node is better.
|
|
130
|
+
if (g.c <= n.c)
|
|
131
|
+
return;
|
|
132
|
+
// New node is better.
|
|
133
|
+
g.d = true;
|
|
134
|
+
this.grid[i] = n;
|
|
135
|
+
this.pool.add(n);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function idx(r, c, cols) {
|
|
139
|
+
return r * cols + c;
|
|
140
|
+
}
|
|
100
141
|
function compare(a, b) {
|
|
101
|
-
//
|
|
142
|
+
// lowest cost then progress
|
|
102
143
|
return a.c - b.c || b.ai + b.bi - a.ai - a.bi;
|
|
103
144
|
}
|
|
104
145
|
//# sourceMappingURL=distanceAStarWeighted.js.map
|
|
@@ -23,7 +23,7 @@ function vizWidth(s) {
|
|
|
23
23
|
function formatExResult(ex) {
|
|
24
24
|
if (!ex)
|
|
25
25
|
return '<undefined>';
|
|
26
|
-
const { cost, segments } = ex;
|
|
26
|
+
const { cost, segments, penalty } = ex;
|
|
27
27
|
const asString = segments.map(({ a, b, c, p }) => ({
|
|
28
28
|
a: `<${a}>`,
|
|
29
29
|
b: `<${b}>`,
|
|
@@ -47,7 +47,8 @@ function formatExResult(ex) {
|
|
|
47
47
|
const b = 'b: |' + parts.map(({ b, w }) => pR(b, w)).join('|') + '|';
|
|
48
48
|
const c = 'c: |' + parts.map(({ c, w }) => pL(c, w)).join('|') + '|';
|
|
49
49
|
const p = 'p: |' + parts.map(({ p, w }) => pL(p, w)).join('|') + '|';
|
|
50
|
-
|
|
50
|
+
const penaltyMsg = penalty ? `[+${penalty}]` : '';
|
|
51
|
+
return `<${ex.a.slice(1, -1)}> -> <${ex.b.slice(1, -1)}> (${cost - penalty}${penaltyMsg})\n${[a, b, c, p].join('\n')}\n`;
|
|
51
52
|
}
|
|
52
53
|
exports.formatExResult = formatExResult;
|
|
53
54
|
function formattedDistance(wordA, wordB, weightMap, cost) {
|
|
@@ -45,12 +45,24 @@ export interface WeightMap {
|
|
|
45
45
|
readonly insDel: TrieCost;
|
|
46
46
|
readonly replace: TrieTrieCost;
|
|
47
47
|
readonly swap: TrieTrieCost;
|
|
48
|
+
readonly adjustments: Map<string, PenaltyAdjustment>;
|
|
48
49
|
calcInsDelCosts(pos: CostPosition): Iterable<CostPosition>;
|
|
49
50
|
calcSwapCosts(pos: CostPosition): Iterable<CostPosition>;
|
|
50
51
|
calcReplaceCosts(pos: CostPosition): Iterable<CostPosition>;
|
|
52
|
+
calcAdjustment(word: string): number;
|
|
53
|
+
}
|
|
54
|
+
export interface PenaltyAdjustment {
|
|
55
|
+
/** Penalty Identifier */
|
|
56
|
+
id: string;
|
|
57
|
+
/** RegExp Pattern to match */
|
|
58
|
+
regexp: RegExp;
|
|
59
|
+
/** Penalty to apply */
|
|
60
|
+
penalty: number;
|
|
51
61
|
}
|
|
52
62
|
export declare function createWeightMap(...defs: SuggestionCostMapDef[]): WeightMap;
|
|
53
63
|
export declare function addDefToWeightMap(map: WeightMap, def: SuggestionCostMapDef, ...defs: SuggestionCostMapDef[]): WeightMap;
|
|
64
|
+
export declare function addAdjustment(map: WeightMap, ...adjustments: PenaltyAdjustment[]): WeightMap;
|
|
65
|
+
export declare function addAdjustment(map: WeightMap, adjustment: PenaltyAdjustment): WeightMap;
|
|
54
66
|
export declare function addDefsToWeightMap(map: WeightMap, defs: SuggestionCostMapDef[]): WeightMap;
|
|
55
67
|
export declare function splitMapSubstringsIterable(map: string): Iterable<string>;
|
|
56
68
|
export declare function splitMapSubstrings(map: string): string[];
|
|
@@ -74,11 +86,13 @@ export declare function prettyPrintReplace(trie: TrieTrieCost, pfx?: string, ind
|
|
|
74
86
|
export declare function prettyPrintSwap(trie: TrieTrieCost, pfx?: string, indent?: string): string;
|
|
75
87
|
export declare function prettyPrintWeightMap(map: WeightMap): string;
|
|
76
88
|
export declare function lookupReplaceCost(map: WeightMap, a: string, b: string): undefined | number;
|
|
89
|
+
declare function normalizeDef(def: SuggestionCostMapDef): SuggestionCostMapDef;
|
|
77
90
|
export declare const __testing__: {
|
|
78
|
-
splitMap: typeof splitMap;
|
|
79
|
-
splitMapSubstrings: typeof splitMapSubstrings;
|
|
80
91
|
findTrieCostPrefixes: typeof findTrieCostPrefixes;
|
|
81
92
|
findTrieTrieCostPrefixes: typeof findTrieTrieCostPrefixes;
|
|
93
|
+
normalizeDef: typeof normalizeDef;
|
|
94
|
+
splitMap: typeof splitMap;
|
|
95
|
+
splitMapSubstrings: typeof splitMapSubstrings;
|
|
82
96
|
};
|
|
83
97
|
export {};
|
|
84
98
|
//# sourceMappingURL=weightedMaps.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.__testing__ = exports.lookupReplaceCost = exports.prettyPrintWeightMap = exports.prettyPrintSwap = exports.prettyPrintReplace = exports.splitMapSubstrings = exports.splitMapSubstringsIterable = exports.addDefsToWeightMap = exports.addDefToWeightMap = exports.createWeightMap = void 0;
|
|
3
|
+
exports.__testing__ = exports.lookupReplaceCost = exports.prettyPrintWeightMap = exports.prettyPrintSwap = exports.prettyPrintReplace = exports.splitMapSubstrings = exports.splitMapSubstringsIterable = exports.addDefsToWeightMap = exports.addAdjustment = exports.addDefToWeightMap = exports.createWeightMap = void 0;
|
|
4
|
+
const suggestCollector_1 = require("../suggestions/suggestCollector");
|
|
5
|
+
const matchPossibleWordSeparators = /[+∙•・●]/g;
|
|
4
6
|
function createWeightMap(...defs) {
|
|
5
7
|
const map = _createWeightMap();
|
|
6
8
|
addDefsToWeightMap(map, defs);
|
|
@@ -11,13 +13,21 @@ function addDefToWeightMap(map, ...defs) {
|
|
|
11
13
|
return addDefsToWeightMap(map, defs);
|
|
12
14
|
}
|
|
13
15
|
exports.addDefToWeightMap = addDefToWeightMap;
|
|
16
|
+
function addAdjustment(map, ...adjustments) {
|
|
17
|
+
for (const adj of adjustments) {
|
|
18
|
+
map.adjustments.set(adj.id, adj);
|
|
19
|
+
}
|
|
20
|
+
return map;
|
|
21
|
+
}
|
|
22
|
+
exports.addAdjustment = addAdjustment;
|
|
14
23
|
function addDefsToWeightMap(map, defs) {
|
|
15
24
|
function addSet(set, def) {
|
|
16
25
|
addSetToTrieCost(map.insDel, set, def.insDel, def.penalty);
|
|
17
26
|
addSetToTrieTrieCost(map.replace, set, def.replace, def.penalty);
|
|
18
27
|
addSetToTrieTrieCost(map.swap, set, def.swap, def.penalty);
|
|
19
28
|
}
|
|
20
|
-
for (const
|
|
29
|
+
for (const _def of defs) {
|
|
30
|
+
const def = normalizeDef(_def);
|
|
21
31
|
const mapSets = splitMap(def);
|
|
22
32
|
mapSets.forEach((s) => addSet(s, def));
|
|
23
33
|
}
|
|
@@ -178,6 +188,7 @@ class _WeightedMap {
|
|
|
178
188
|
this.insDel = {};
|
|
179
189
|
this.replace = {};
|
|
180
190
|
this.swap = {};
|
|
191
|
+
this.adjustments = new Map();
|
|
181
192
|
}
|
|
182
193
|
*calcInsDelCosts(pos) {
|
|
183
194
|
const { a, ai, b, bi, c, p } = pos;
|
|
@@ -212,6 +223,20 @@ class _WeightedMap {
|
|
|
212
223
|
}
|
|
213
224
|
}
|
|
214
225
|
}
|
|
226
|
+
calcAdjustment(word) {
|
|
227
|
+
let penalty = 0;
|
|
228
|
+
for (const adj of this.adjustments.values()) {
|
|
229
|
+
if (adj.regexp.global) {
|
|
230
|
+
for (const _m of word.matchAll(adj.regexp)) {
|
|
231
|
+
penalty += adj.penalty;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else if (adj.regexp.test(word)) {
|
|
235
|
+
penalty += adj.penalty;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return penalty;
|
|
239
|
+
}
|
|
215
240
|
}
|
|
216
241
|
function prettyPrintInsDel(trie, pfx = '', indent = ' ') {
|
|
217
242
|
function* walk() {
|
|
@@ -262,10 +287,18 @@ function lookupReplaceCost(map, a, b) {
|
|
|
262
287
|
return t === null || t === void 0 ? void 0 : t.c;
|
|
263
288
|
}
|
|
264
289
|
exports.lookupReplaceCost = lookupReplaceCost;
|
|
290
|
+
function normalizeDef(def) {
|
|
291
|
+
const { map, ...rest } = def;
|
|
292
|
+
return { ...rest, map: normalizeMap(map) };
|
|
293
|
+
}
|
|
294
|
+
function normalizeMap(map) {
|
|
295
|
+
return map.replace(matchPossibleWordSeparators, suggestCollector_1.DEFAULT_COMPOUNDED_WORD_SEPARATOR);
|
|
296
|
+
}
|
|
265
297
|
exports.__testing__ = {
|
|
266
|
-
splitMap,
|
|
267
|
-
splitMapSubstrings,
|
|
268
298
|
findTrieCostPrefixes,
|
|
269
299
|
findTrieTrieCostPrefixes,
|
|
300
|
+
normalizeDef,
|
|
301
|
+
splitMap,
|
|
302
|
+
splitMapSubstrings,
|
|
270
303
|
};
|
|
271
304
|
//# sourceMappingURL=weightedMaps.js.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { DictionaryInformation } from '../models/DictionaryInformation';
|
|
2
2
|
import type { SuggestionCostMapDef } from '../models/suggestionCostsDef';
|
|
3
|
+
import { PenaltyAdjustment } from '../distance/weightedMaps';
|
|
3
4
|
export declare function mapDictionaryInformation(dictInfo: DictionaryInformation): SuggestionCostMapDef[];
|
|
5
|
+
export declare function mapDictionaryInformationToAdjustment(dictInfo: DictionaryInformation): PenaltyAdjustment[];
|
|
4
6
|
//# sourceMappingURL=mapDictionaryInfo.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapDictionaryInformation = void 0;
|
|
3
|
+
exports.mapDictionaryInformationToAdjustment = exports.mapDictionaryInformation = void 0;
|
|
4
4
|
const cspell_pipe_1 = require("@cspell/cspell-pipe");
|
|
5
5
|
const locale_1 = require("../models/locale");
|
|
6
6
|
const util_1 = require("../utils/util");
|
|
@@ -52,4 +52,18 @@ function processAccents(accents, editCost) {
|
|
|
52
52
|
const cs = toCharSets(accents, '\u0300-\u0341', editCost.accentCosts);
|
|
53
53
|
return cs.map((cs) => (0, mapToSuggestionCostDef_1.parseAccents)(cs, editCost)).filter(util_1.isDefined);
|
|
54
54
|
}
|
|
55
|
+
function mapDictionaryInformationToAdjustment(dictInfo) {
|
|
56
|
+
if (!dictInfo.adjustments)
|
|
57
|
+
return [];
|
|
58
|
+
return dictInfo.adjustments.map(mapAdjustment);
|
|
59
|
+
}
|
|
60
|
+
exports.mapDictionaryInformationToAdjustment = mapDictionaryInformationToAdjustment;
|
|
61
|
+
function mapAdjustment(adj) {
|
|
62
|
+
const { id, regexp, penalty } = adj;
|
|
63
|
+
return {
|
|
64
|
+
id: id,
|
|
65
|
+
regexp: new RegExp(regexp),
|
|
66
|
+
penalty,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
55
69
|
//# sourceMappingURL=mapDictionaryInfo.js.map
|
|
@@ -10,9 +10,29 @@ const defaultDefs = [
|
|
|
10
10
|
penalty: 200,
|
|
11
11
|
},
|
|
12
12
|
];
|
|
13
|
+
const defaultAdjustments = [
|
|
14
|
+
{
|
|
15
|
+
id: 'compound-case-change',
|
|
16
|
+
regexp: /\p{Ll}∙\p{Lu}/gu,
|
|
17
|
+
penalty: 1000,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: 'short-compounds-1',
|
|
21
|
+
regexp: /^[^∙]{0,2}(?=∙)|∙[^∙]{0,2}(?=∙|$)/gm,
|
|
22
|
+
penalty: 100,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: 'short-compounds-3',
|
|
26
|
+
regexp: /^[^∙]{3}(?=∙)|∙[^∙]{3}(?=∙|$)/gm,
|
|
27
|
+
penalty: 50,
|
|
28
|
+
},
|
|
29
|
+
];
|
|
13
30
|
function mapDictionaryInformationToWeightMap(dictInfo) {
|
|
14
31
|
const defs = (0, mapDictionaryInfo_1.mapDictionaryInformation)(dictInfo).concat(defaultDefs);
|
|
15
|
-
|
|
32
|
+
const adjustments = (0, mapDictionaryInfo_1.mapDictionaryInformationToAdjustment)(dictInfo);
|
|
33
|
+
const map = (0, weightedMaps_1.createWeightMap)(...defs);
|
|
34
|
+
(0, weightedMaps_1.addAdjustment)(map, ...defaultAdjustments, ...adjustments);
|
|
35
|
+
return map;
|
|
16
36
|
}
|
|
17
37
|
exports.mapDictionaryInformationToWeightMap = mapDictionaryInformationToWeightMap;
|
|
18
38
|
exports.__testing__ = {};
|
|
@@ -13,7 +13,9 @@ const MAX_COST_SCALE = 0.5;
|
|
|
13
13
|
// max allowed cost scale should be a bit over 50% to allow for suggestions to short words, but not too high to have too many suggestions.
|
|
14
14
|
const MAX_ALLOWED_COST_SCALE = 1.03 * MAX_COST_SCALE;
|
|
15
15
|
const collator = new Intl.Collator();
|
|
16
|
-
|
|
16
|
+
// This is a bit broken, it was supposed to also include JOIN_SEPARATOR (`+`)
|
|
17
|
+
// Add it back later.
|
|
18
|
+
const regexSeparator = new RegExp(`[${(0, util_1.regexQuote)(walker_1.WORD_SEPARATOR)}]`, 'g');
|
|
17
19
|
const wordLengthCost = [0, 50, 25, 5, 0];
|
|
18
20
|
const EXTRA_WORD_COST = 5;
|
|
19
21
|
exports.DEFAULT_COMPOUNDED_WORD_SEPARATOR = '∙';
|
|
@@ -66,9 +68,7 @@ function suggestionCollector(wordToMatch, options) {
|
|
|
66
68
|
for (; i < sorted.length && sorted[i].cost <= maxCost; ++i) {
|
|
67
69
|
/* empty */
|
|
68
70
|
}
|
|
69
|
-
const deleted = [];
|
|
70
71
|
for (; i < sorted.length; ++i) {
|
|
71
|
-
deleted.push(sorted[i]);
|
|
72
72
|
sugs.delete(sorted[i].word);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -150,8 +150,9 @@ function suggestionCollector(wordToMatch, options) {
|
|
|
150
150
|
const sorted = values.sort(compSuggestionResults).map(cleanCompoundResult);
|
|
151
151
|
let i = Math.min(sorted.length, numSuggestions) - 1;
|
|
152
152
|
const limit = includeTies ? sorted.length : Math.min(sorted.length, numSuggestions);
|
|
153
|
-
const
|
|
154
|
-
|
|
153
|
+
const iCost = sorted[i].cost;
|
|
154
|
+
const maxCost = Math.min(iCost, weightMap ? changeLimit * BASE_COST - 1 : iCost);
|
|
155
|
+
for (i = 1; i < limit && sorted[i].cost <= maxCost; ++i) {
|
|
155
156
|
// loop
|
|
156
157
|
}
|
|
157
158
|
sorted.length = i;
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -66,4 +66,5 @@ export declare type RemoveUndefined<T> = {
|
|
|
66
66
|
* Make all `undefined` optional and removes the `undefined`
|
|
67
67
|
*/
|
|
68
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;
|
|
69
70
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class AutoCacheMap<T, U> extends Map<T, U> {
|
|
2
|
+
readonly autoFn: (v: T) => U;
|
|
3
|
+
constructor(autoFn: (v: T) => U);
|
|
4
|
+
get(v: T): U;
|
|
5
|
+
}
|
|
6
|
+
export declare class AutoCacheWeakMap<T extends object, U> extends WeakMap<T, U> {
|
|
7
|
+
readonly autoFn: (v: T) => U;
|
|
8
|
+
constructor(autoFn: (v: T) => U);
|
|
9
|
+
get(v: T): U;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=autoCacheMap.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AutoCacheWeakMap = exports.AutoCacheMap = void 0;
|
|
4
|
+
class AutoCacheMap extends Map {
|
|
5
|
+
constructor(autoFn) {
|
|
6
|
+
super();
|
|
7
|
+
this.autoFn = autoFn;
|
|
8
|
+
}
|
|
9
|
+
get(v) {
|
|
10
|
+
const r = super.get(v);
|
|
11
|
+
if (r !== undefined)
|
|
12
|
+
return r;
|
|
13
|
+
const u = this.autoFn(v);
|
|
14
|
+
super.set(v, u);
|
|
15
|
+
return u;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.AutoCacheMap = AutoCacheMap;
|
|
19
|
+
class AutoCacheWeakMap extends WeakMap {
|
|
20
|
+
constructor(autoFn) {
|
|
21
|
+
super();
|
|
22
|
+
this.autoFn = autoFn;
|
|
23
|
+
}
|
|
24
|
+
get(v) {
|
|
25
|
+
const r = super.get(v);
|
|
26
|
+
if (r !== undefined)
|
|
27
|
+
return r;
|
|
28
|
+
const u = this.autoFn(v);
|
|
29
|
+
super.set(v, u);
|
|
30
|
+
return u;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.AutoCacheWeakMap = AutoCacheWeakMap;
|
|
34
|
+
//# sourceMappingURL=autoCacheMap.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function memorizer<T, K>(fn: (...p: [...K[]]) => T): (...p: [...K[]]) => T;
|
|
2
|
+
export declare function memorizer<T, K0, K1, K2, K3>(fn: (...p: [K0, K1, K2, K3]) => T): (...p: [K0, K1, K2, K3]) => T;
|
|
3
|
+
export declare function memorizer<T, K0, K1, K2>(fn: (...p: [K0, K1, K2]) => T): (...p: [K0, K1, K2]) => T;
|
|
4
|
+
export declare function memorizer<T, K0, K1>(fn: (...p: [K0, K1]) => T): (...p: [K0, K1]) => T;
|
|
5
|
+
export declare function memorizer<T, K0>(fn: (...p: [K0]) => T): (...p: [K0]) => T;
|
|
6
|
+
//# sourceMappingURL=memorizer.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.memorizer = void 0;
|
|
4
|
+
function memorizer(fn) {
|
|
5
|
+
const r = {};
|
|
6
|
+
function find(p) {
|
|
7
|
+
var _a;
|
|
8
|
+
let n = r;
|
|
9
|
+
for (const k of p) {
|
|
10
|
+
if (!n)
|
|
11
|
+
break;
|
|
12
|
+
n = (_a = n.c) === null || _a === void 0 ? void 0 : _a.get(k);
|
|
13
|
+
}
|
|
14
|
+
return n;
|
|
15
|
+
}
|
|
16
|
+
function set(p, v) {
|
|
17
|
+
var _a;
|
|
18
|
+
let n = r;
|
|
19
|
+
for (const k of p) {
|
|
20
|
+
const c = (_a = n.c) === null || _a === void 0 ? void 0 : _a.get(k);
|
|
21
|
+
if (c) {
|
|
22
|
+
n = c;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const r = {};
|
|
26
|
+
n.c = n.c || new Map();
|
|
27
|
+
n.c.set(k, r);
|
|
28
|
+
n = r;
|
|
29
|
+
}
|
|
30
|
+
n.v = v;
|
|
31
|
+
}
|
|
32
|
+
return (...p) => {
|
|
33
|
+
const f = find(p);
|
|
34
|
+
if (f && 'v' in f) {
|
|
35
|
+
return f.v;
|
|
36
|
+
}
|
|
37
|
+
const v = fn(...p);
|
|
38
|
+
set(p, v);
|
|
39
|
+
return v;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
exports.memorizer = memorizer;
|
|
43
|
+
//# sourceMappingURL=memorizer.js.map
|
package/dist/lib/utils/util.js
CHANGED
|
@@ -51,7 +51,7 @@ exports.replaceAll = replaceAll;
|
|
|
51
51
|
* @returns text that can be used in a regexp.
|
|
52
52
|
*/
|
|
53
53
|
function regexQuote(text) {
|
|
54
|
-
return text.replace(/[[\]\-+(){},|*.\\]/g, '\\$1');
|
|
54
|
+
return text.replace(/([[\]\-+(){},|*.\\])/g, '\\$1');
|
|
55
55
|
}
|
|
56
56
|
exports.regexQuote = regexQuote;
|
|
57
57
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-trie-lib",
|
|
3
|
-
"version": "5.18.
|
|
3
|
+
"version": "5.18.5",
|
|
4
4
|
"description": "Trie Data Structure to support cspell.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/streetsidesoftware/cspell#readme",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@cspell/cspell-pipe": "^5.18.
|
|
40
|
+
"@cspell/cspell-pipe": "^5.18.5",
|
|
41
41
|
"fs-extra": "^10.0.0",
|
|
42
42
|
"gensequence": "^3.1.1"
|
|
43
43
|
},
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"node": ">=12.13.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@cspell/cspell-types": "^5.18.
|
|
49
|
-
"@cspell/dict-en_us": "^2.1.
|
|
48
|
+
"@cspell/cspell-types": "^5.18.5",
|
|
49
|
+
"@cspell/dict-en_us": "^2.1.7",
|
|
50
50
|
"@cspell/dict-es-es": "^2.1.0",
|
|
51
51
|
"@types/fs-extra": "^9.0.13",
|
|
52
|
-
"@types/node": "^17.0.
|
|
53
|
-
"jest": "^27.
|
|
52
|
+
"@types/node": "^17.0.18",
|
|
53
|
+
"jest": "^27.5.1",
|
|
54
54
|
"rimraf": "^3.0.2"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "bff6b01340bde5ca7a89860868e179592eaa7520"
|
|
57
57
|
}
|