cspell-trie-lib 10.0.1 → 10.1.0
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/index.d.ts +418 -419
- package/dist/index.js +39 -33
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -614,10 +614,11 @@ function* walkerWordsITrie(root) {
|
|
|
614
614
|
let depth = 0;
|
|
615
615
|
const stack = [];
|
|
616
616
|
const entries = root.entries();
|
|
617
|
+
const c = Array.isArray(entries) ? entries : [...entries];
|
|
617
618
|
stack[depth] = {
|
|
618
619
|
t: "",
|
|
619
620
|
n: root,
|
|
620
|
-
c
|
|
621
|
+
c,
|
|
621
622
|
ci: 0
|
|
622
623
|
};
|
|
623
624
|
while (depth >= 0) {
|
|
@@ -1303,7 +1304,7 @@ function highest(a, b) {
|
|
|
1303
1304
|
return a >= b ? a : b;
|
|
1304
1305
|
}
|
|
1305
1306
|
function normalize(s) {
|
|
1306
|
-
const f = new Set([s]);
|
|
1307
|
+
const f = /* @__PURE__ */ new Set([s]);
|
|
1307
1308
|
f.add(s.normalize("NFC"));
|
|
1308
1309
|
f.add(s.normalize("NFD"));
|
|
1309
1310
|
return f;
|
|
@@ -1748,7 +1749,7 @@ function replaceAllFactory(match, replaceWithText) {
|
|
|
1748
1749
|
const defaultMaxNumberSuggestions = 10;
|
|
1749
1750
|
const BASE_COST = 100;
|
|
1750
1751
|
const MAX_NUM_CHANGES = 5;
|
|
1751
|
-
const MAX_ALLOWED_COST_SCALE =
|
|
1752
|
+
const MAX_ALLOWED_COST_SCALE = .515;
|
|
1752
1753
|
const collator = new Intl.Collator();
|
|
1753
1754
|
const regexSeparator = new RegExp(`[${regexQuote(" ")}]`, "g");
|
|
1754
1755
|
const wordLengthCost = [
|
|
@@ -3256,7 +3257,7 @@ var StringTableBuilder = class StringTableBuilder {
|
|
|
3256
3257
|
}
|
|
3257
3258
|
#build() {
|
|
3258
3259
|
this.#locked = true;
|
|
3259
|
-
if (!this.#data.length) return new StringTable([], new Uint8Array(0), 8);
|
|
3260
|
+
if (!this.#data.length) return new StringTable([], /* @__PURE__ */ new Uint8Array(0), 8);
|
|
3260
3261
|
const sortedBySize = this.#data.map((b, i) => ({
|
|
3261
3262
|
b,
|
|
3262
3263
|
i
|
|
@@ -3339,7 +3340,7 @@ function encodeStringTableToBinary(table, endian) {
|
|
|
3339
3340
|
* @returns The decoded StringTable.
|
|
3340
3341
|
*/
|
|
3341
3342
|
function decodeStringTableFromBinary(data, endian) {
|
|
3342
|
-
if (!data?.length) return new StringTable([], new Uint8Array(0), 8);
|
|
3343
|
+
if (!data?.length) return new StringTable([], /* @__PURE__ */ new Uint8Array(0), 8);
|
|
3343
3344
|
const reader = new BinaryDataReader(data, getStringTableBinaryFormat(), endian);
|
|
3344
3345
|
const indexBits = reader.getUint8("indexBits");
|
|
3345
3346
|
const strLenBits = reader.getUint8("strLenBits");
|
|
@@ -3416,7 +3417,7 @@ function expandRange(a, b) {
|
|
|
3416
3417
|
* @returns the set of found cases.
|
|
3417
3418
|
*/
|
|
3418
3419
|
function caseForms(letter, locale) {
|
|
3419
|
-
const forms = new Set([letter]);
|
|
3420
|
+
const forms = /* @__PURE__ */ new Set([letter]);
|
|
3420
3421
|
function tryCases(s) {
|
|
3421
3422
|
forms.add(s.toLocaleLowerCase(locale));
|
|
3422
3423
|
forms.add(s.toLocaleUpperCase(locale));
|
|
@@ -3431,7 +3432,7 @@ function caseForms(letter, locale) {
|
|
|
3431
3432
|
* @returns combined set of possible forms.
|
|
3432
3433
|
*/
|
|
3433
3434
|
function accentForms(letter) {
|
|
3434
|
-
return new Set([
|
|
3435
|
+
return /* @__PURE__ */ new Set([
|
|
3435
3436
|
letter,
|
|
3436
3437
|
letter.normalize("NFC"),
|
|
3437
3438
|
letter.normalize("NFD")
|
|
@@ -3675,7 +3676,8 @@ var CharIndex = class CharIndex {
|
|
|
3675
3676
|
return { charIndex: [...this.charIndex].join("") };
|
|
3676
3677
|
}
|
|
3677
3678
|
static fromJSON(json) {
|
|
3678
|
-
|
|
3679
|
+
const charIndex = new Set(json.charIndex);
|
|
3680
|
+
return new CharIndex(charIndex);
|
|
3679
3681
|
}
|
|
3680
3682
|
static fromIterable(charIndex) {
|
|
3681
3683
|
const charSet = /* @__PURE__ */ new Set();
|
|
@@ -3892,7 +3894,7 @@ function optimizeNodesWithStringTable(src) {
|
|
|
3892
3894
|
const endPerf = measurePerf("TrieBlob.optimizeNodesWithStringTable");
|
|
3893
3895
|
const { nodes, stringTableBuilder: builder } = copyNodesAndStringTable(src);
|
|
3894
3896
|
const multipleNodeRefs = calcHasMultipleReferences(nodes);
|
|
3895
|
-
const multiStringRefs = new Set([0]);
|
|
3897
|
+
const multiStringRefs = /* @__PURE__ */ new Set([0]);
|
|
3896
3898
|
if (!builder.length) builder.addString("");
|
|
3897
3899
|
walkNodes(nodes, 0, { after: processNode });
|
|
3898
3900
|
const r = {
|
|
@@ -4899,7 +4901,7 @@ var TrieBlobBuilder = class TrieBlobBuilder {
|
|
|
4899
4901
|
}
|
|
4900
4902
|
assert(this.nodes.length === 2);
|
|
4901
4903
|
const eowNodeIndex = 1;
|
|
4902
|
-
const eowShifted =
|
|
4904
|
+
const eowShifted = 256;
|
|
4903
4905
|
const nodes = this.nodes;
|
|
4904
4906
|
const stack = [{
|
|
4905
4907
|
nodeIdx: 0,
|
|
@@ -5134,7 +5136,7 @@ var TrieBlobBuilder = class TrieBlobBuilder {
|
|
|
5134
5136
|
const NodeMaskEOW = 256;
|
|
5135
5137
|
const tf = new TrieBlobBuilder(void 0, root);
|
|
5136
5138
|
const IdxEOW = tf.IdxEOW;
|
|
5137
|
-
const known = new Map([[root, 0]]);
|
|
5139
|
+
const known = /* @__PURE__ */ new Map([[root, 0]]);
|
|
5138
5140
|
function resolveNode(n) {
|
|
5139
5141
|
if (n.f && !n.c) return IdxEOW;
|
|
5140
5142
|
const node = [n.f ? NodeMaskEOW : 0];
|
|
@@ -5194,7 +5196,7 @@ var TrieBlobBuilder = class TrieBlobBuilder {
|
|
|
5194
5196
|
const NodeMaskEOW = 256;
|
|
5195
5197
|
const tf = new TrieBlobBuilder(void 0, root);
|
|
5196
5198
|
const IdxEOW = tf.IdxEOW;
|
|
5197
|
-
const known = new Map([[root.id, 0]]);
|
|
5199
|
+
const known = /* @__PURE__ */ new Map([[root.id, 0]]);
|
|
5198
5200
|
function resolveNode(n) {
|
|
5199
5201
|
if (n.eow && !n.hasChildren()) return IdxEOW;
|
|
5200
5202
|
const node = [n.eow ? NodeMaskEOW : 0];
|
|
@@ -5485,7 +5487,8 @@ var ITrieImpl = class ITrieImpl {
|
|
|
5485
5487
|
static create(words, info) {
|
|
5486
5488
|
const builder = new TrieBlobBuilder(info);
|
|
5487
5489
|
builder.insert(words);
|
|
5488
|
-
|
|
5490
|
+
const root = builder.build();
|
|
5491
|
+
return new ITrieImpl(root);
|
|
5489
5492
|
}
|
|
5490
5493
|
createFindOptions(options) {
|
|
5491
5494
|
return createFindOptions$1(options);
|
|
@@ -6096,10 +6099,12 @@ var TrieNodeTrie = class TrieNodeTrie {
|
|
|
6096
6099
|
return this._size ??= countNodes(this.root);
|
|
6097
6100
|
}
|
|
6098
6101
|
static createFromWords(words, options) {
|
|
6099
|
-
|
|
6102
|
+
const root = createTrieRootFromList(words, options);
|
|
6103
|
+
return new TrieNodeTrie(root);
|
|
6100
6104
|
}
|
|
6101
6105
|
static createFromWordsAndConsolidate(words, options) {
|
|
6102
|
-
|
|
6106
|
+
const root = createTrieRootFromList(words, options);
|
|
6107
|
+
return new TrieNodeTrie(consolidate(root));
|
|
6103
6108
|
}
|
|
6104
6109
|
};
|
|
6105
6110
|
//#endregion
|
|
@@ -6434,7 +6439,7 @@ function convertToTrieRefNodes(root) {
|
|
|
6434
6439
|
f: 1,
|
|
6435
6440
|
c: void 0
|
|
6436
6441
|
};
|
|
6437
|
-
const tallies = new Map([[eow, 0]]);
|
|
6442
|
+
const tallies = /* @__PURE__ */ new Map([[eow, 0]]);
|
|
6438
6443
|
let count = 0;
|
|
6439
6444
|
const cached = /* @__PURE__ */ new Map();
|
|
6440
6445
|
const rollupTally = /* @__PURE__ */ new Map();
|
|
@@ -6910,7 +6915,10 @@ ${INLINE_DATA_COMMENT_LINE}* `;
|
|
|
6910
6915
|
return;
|
|
6911
6916
|
}
|
|
6912
6917
|
if (node.c) {
|
|
6913
|
-
if (depth > 0 && depth <= 2)
|
|
6918
|
+
if (depth > 0 && depth <= 2) {
|
|
6919
|
+
const chars = wordChars.slice(0, depth).map(escape).join("");
|
|
6920
|
+
yield* emit(comment_begin + chars + comment_end);
|
|
6921
|
+
}
|
|
6914
6922
|
cache.set(node, count++);
|
|
6915
6923
|
const c = Object.entries(node.c).sort((a, b) => a[0] < b[0] ? -1 : 1);
|
|
6916
6924
|
for (const [s, n] of c) {
|
|
@@ -7322,7 +7330,7 @@ var TrieNodeBuilder = class {
|
|
|
7322
7330
|
};
|
|
7323
7331
|
//#endregion
|
|
7324
7332
|
//#region src/lib/io/importV3.ts
|
|
7325
|
-
const characterMap = new Map([
|
|
7333
|
+
const characterMap = new Map([.../* @__PURE__ */ new Map([
|
|
7326
7334
|
["\n", "\\n"],
|
|
7327
7335
|
["\r", "\\r"],
|
|
7328
7336
|
["\\", "\\\\"]
|
|
@@ -7434,7 +7442,7 @@ function parseStream(radix) {
|
|
|
7434
7442
|
function parseIgnore(acc, _) {
|
|
7435
7443
|
return acc;
|
|
7436
7444
|
}
|
|
7437
|
-
const parsers = new Map([
|
|
7445
|
+
const parsers = /* @__PURE__ */ new Map([
|
|
7438
7446
|
["$", parseEOW],
|
|
7439
7447
|
["<", parseBack],
|
|
7440
7448
|
["#", parseReference],
|
|
@@ -7508,7 +7516,7 @@ const insertSpaceCost = -1;
|
|
|
7508
7516
|
const mapSubCost = opCosts.visuallySimilar;
|
|
7509
7517
|
const maxCostScale = opCosts.wordLengthCostFactor;
|
|
7510
7518
|
const discourageInsertCost = baseCost;
|
|
7511
|
-
const setOfSeparators = new Set(["+", " "]);
|
|
7519
|
+
const setOfSeparators = /* @__PURE__ */ new Set(["+", " "]);
|
|
7512
7520
|
function suggest(root, word, options = {}) {
|
|
7513
7521
|
const opts = createSuggestionOptions(options);
|
|
7514
7522
|
const collector = suggestionCollector(word, clean(opts));
|
|
@@ -7544,9 +7552,7 @@ function* genCompoundableSuggestions(root, word, options = {}) {
|
|
|
7544
7552
|
case "number":
|
|
7545
7553
|
costLimit = maxCost;
|
|
7546
7554
|
break;
|
|
7547
|
-
case "symbol":
|
|
7548
|
-
stopNow = true;
|
|
7549
|
-
break;
|
|
7555
|
+
case "symbol": stopNow = true;
|
|
7550
7556
|
}
|
|
7551
7557
|
}
|
|
7552
7558
|
const a = 0;
|
|
@@ -8042,11 +8048,13 @@ var TrieBuilder = class {
|
|
|
8042
8048
|
const n = this.transforms.get(node)?.get(s.join(""));
|
|
8043
8049
|
if (n) return this.#tryCacheFrozen(n);
|
|
8044
8050
|
}
|
|
8045
|
-
if (!s.length)
|
|
8046
|
-
|
|
8047
|
-
|
|
8048
|
-
|
|
8049
|
-
|
|
8051
|
+
if (!s.length) {
|
|
8052
|
+
if (!node.c) return this._eow;
|
|
8053
|
+
else {
|
|
8054
|
+
node = this.#copyIfFrozen(node);
|
|
8055
|
+
node.f = this._eow.f;
|
|
8056
|
+
return node;
|
|
8057
|
+
}
|
|
8050
8058
|
}
|
|
8051
8059
|
const head = s[0];
|
|
8052
8060
|
const tail = s.slice(1);
|
|
@@ -8249,9 +8257,7 @@ function createDictionaryLineParserMapper(options) {
|
|
|
8249
8257
|
case "no-generate-alternatives":
|
|
8250
8258
|
stripCaseAndAccents = false;
|
|
8251
8259
|
break;
|
|
8252
|
-
case "generate-alternatives":
|
|
8253
|
-
stripCaseAndAccents = true;
|
|
8254
|
-
break;
|
|
8260
|
+
case "generate-alternatives": stripCaseAndAccents = true;
|
|
8255
8261
|
}
|
|
8256
8262
|
}
|
|
8257
8263
|
return line.slice(0, idx).trim();
|
|
@@ -8541,7 +8547,7 @@ const specialCharacters = stringToCharSet([
|
|
|
8541
8547
|
"0123456789",
|
|
8542
8548
|
"`~!@#$%^&*()_-+=[]{};:'\"<>,./?\\|"
|
|
8543
8549
|
].join(""));
|
|
8544
|
-
const specialCharacterMap = new Map([
|
|
8550
|
+
const specialCharacterMap = /* @__PURE__ */ new Map([
|
|
8545
8551
|
["\n", "\\n"],
|
|
8546
8552
|
["\r", "\\r"],
|
|
8547
8553
|
["\\", "\\\\"]
|
|
@@ -10971,7 +10977,7 @@ function parseAccents(cs, _editCost) {
|
|
|
10971
10977
|
}
|
|
10972
10978
|
function calcCostsForAccentedLetters(simpleMap, locale, costs) {
|
|
10973
10979
|
const charactersWithAccents = [...pipeSync(splitMap(simpleMap), opMapSync((char) => caseForms(char, locale)), opFlattenSync(), opMapSync((char) => [...accentForms(char)]), opFilterSync((forms) => forms.length > 1))];
|
|
10974
|
-
const replaceAccentMap = [...pipeSync(charactersWithAccents, opMapSync((forms) => new Set([...forms, ...forms.map((char) => stripAccents(char))])), opMapSync((forms) => [...forms].sort()), opFilterSync((forms) => forms.length > 1), opMapSync(joinLetters), opUniqueSync())].join("|");
|
|
10980
|
+
const replaceAccentMap = [...pipeSync(charactersWithAccents, opMapSync((forms) => /* @__PURE__ */ new Set([...forms, ...forms.map((char) => stripAccents(char))])), opMapSync((forms) => [...forms].sort()), opFilterSync((forms) => forms.length > 1), opMapSync(joinLetters), opUniqueSync())].join("|");
|
|
10975
10981
|
const cost = costs.accentCosts;
|
|
10976
10982
|
const costToReplaceAccent = !replaceAccentMap ? [] : [{
|
|
10977
10983
|
map: replaceAccentMap,
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public",
|
|
5
5
|
"provenance": true
|
|
6
6
|
},
|
|
7
|
-
"version": "10.0
|
|
7
|
+
"version": "10.1.0",
|
|
8
8
|
"description": "Trie Data Structure to support cspell.",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"sideEffects": false,
|
|
@@ -62,16 +62,16 @@
|
|
|
62
62
|
"node": ">=22.18.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"@cspell/cspell-types": "10.0
|
|
65
|
+
"@cspell/cspell-types": "10.1.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@cspell/cspell-performance-monitor": "10.0
|
|
69
|
-
"@cspell/cspell-pipe": "10.0
|
|
70
|
-
"@cspell/dict-cpp": "^7.0
|
|
71
|
-
"@cspell/dict-en_us": "^4.4.
|
|
68
|
+
"@cspell/cspell-performance-monitor": "10.1.0",
|
|
69
|
+
"@cspell/cspell-pipe": "10.1.0",
|
|
70
|
+
"@cspell/dict-cpp": "^7.1.0",
|
|
71
|
+
"@cspell/dict-en_us": "^4.4.36",
|
|
72
72
|
"@cspell/dict-es-es": "^3.0.8",
|
|
73
73
|
"@cspell/dict-nl-nl": "^2.4.2",
|
|
74
74
|
"gensequence": "^8.0.8"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "401518c5e37c06fb406aedadb3fc7a1c27eca8e6"
|
|
77
77
|
}
|