cspell-trie-lib 10.0.0 → 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.
Files changed (3) hide show
  1. package/dist/index.d.ts +418 -419
  2. package/dist/index.js +51 -35
  3. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -483,8 +483,17 @@ function _createFindOptions$1(options) {
483
483
  const JOIN_SEPARATOR = "+";
484
484
  const WORD_SEPARATOR = " ";
485
485
  const CompoundWordsMethod = {
486
+ /**
487
+ * Do not compound words.
488
+ */
486
489
  NONE: 0,
490
+ /**
491
+ * Create word compounds separated by spaces.
492
+ */
487
493
  SEPARATE_WORDS: 1,
494
+ /**
495
+ * Create word compounds without separation.
496
+ */
488
497
  JOIN_WORDS: 2,
489
498
  0: "NONE",
490
499
  1: "SEPARATE_WORDS",
@@ -605,10 +614,11 @@ function* walkerWordsITrie(root) {
605
614
  let depth = 0;
606
615
  const stack = [];
607
616
  const entries = root.entries();
617
+ const c = Array.isArray(entries) ? entries : [...entries];
608
618
  stack[depth] = {
609
619
  t: "",
610
620
  n: root,
611
- c: Array.isArray(entries) ? entries : [...entries],
621
+ c,
612
622
  ci: 0
613
623
  };
614
624
  while (depth >= 0) {
@@ -1294,7 +1304,7 @@ function highest(a, b) {
1294
1304
  return a >= b ? a : b;
1295
1305
  }
1296
1306
  function normalize(s) {
1297
- const f = new Set([s]);
1307
+ const f = /* @__PURE__ */ new Set([s]);
1298
1308
  f.add(s.normalize("NFC"));
1299
1309
  f.add(s.normalize("NFD"));
1300
1310
  return f;
@@ -1739,7 +1749,7 @@ function replaceAllFactory(match, replaceWithText) {
1739
1749
  const defaultMaxNumberSuggestions = 10;
1740
1750
  const BASE_COST = 100;
1741
1751
  const MAX_NUM_CHANGES = 5;
1742
- const MAX_ALLOWED_COST_SCALE = 1.03 * .5;
1752
+ const MAX_ALLOWED_COST_SCALE = .515;
1743
1753
  const collator = new Intl.Collator();
1744
1754
  const regexSeparator = new RegExp(`[${regexQuote(" ")}]`, "g");
1745
1755
  const wordLengthCost = [
@@ -3247,7 +3257,7 @@ var StringTableBuilder = class StringTableBuilder {
3247
3257
  }
3248
3258
  #build() {
3249
3259
  this.#locked = true;
3250
- if (!this.#data.length) return new StringTable([], new Uint8Array(0), 8);
3260
+ if (!this.#data.length) return new StringTable([], /* @__PURE__ */ new Uint8Array(0), 8);
3251
3261
  const sortedBySize = this.#data.map((b, i) => ({
3252
3262
  b,
3253
3263
  i
@@ -3330,7 +3340,7 @@ function encodeStringTableToBinary(table, endian) {
3330
3340
  * @returns The decoded StringTable.
3331
3341
  */
3332
3342
  function decodeStringTableFromBinary(data, endian) {
3333
- if (!data?.length) return new StringTable([], new Uint8Array(0), 8);
3343
+ if (!data?.length) return new StringTable([], /* @__PURE__ */ new Uint8Array(0), 8);
3334
3344
  const reader = new BinaryDataReader(data, getStringTableBinaryFormat(), endian);
3335
3345
  const indexBits = reader.getUint8("indexBits");
3336
3346
  const strLenBits = reader.getUint8("strLenBits");
@@ -3407,7 +3417,7 @@ function expandRange(a, b) {
3407
3417
  * @returns the set of found cases.
3408
3418
  */
3409
3419
  function caseForms(letter, locale) {
3410
- const forms = new Set([letter]);
3420
+ const forms = /* @__PURE__ */ new Set([letter]);
3411
3421
  function tryCases(s) {
3412
3422
  forms.add(s.toLocaleLowerCase(locale));
3413
3423
  forms.add(s.toLocaleUpperCase(locale));
@@ -3422,7 +3432,7 @@ function caseForms(letter, locale) {
3422
3432
  * @returns combined set of possible forms.
3423
3433
  */
3424
3434
  function accentForms(letter) {
3425
- return new Set([
3435
+ return /* @__PURE__ */ new Set([
3426
3436
  letter,
3427
3437
  letter.normalize("NFC"),
3428
3438
  letter.normalize("NFD")
@@ -3666,7 +3676,8 @@ var CharIndex = class CharIndex {
3666
3676
  return { charIndex: [...this.charIndex].join("") };
3667
3677
  }
3668
3678
  static fromJSON(json) {
3669
- return new CharIndex(new Set(json.charIndex));
3679
+ const charIndex = new Set(json.charIndex);
3680
+ return new CharIndex(charIndex);
3670
3681
  }
3671
3682
  static fromIterable(charIndex) {
3672
3683
  const charSet = /* @__PURE__ */ new Set();
@@ -3883,7 +3894,7 @@ function optimizeNodesWithStringTable(src) {
3883
3894
  const endPerf = measurePerf("TrieBlob.optimizeNodesWithStringTable");
3884
3895
  const { nodes, stringTableBuilder: builder } = copyNodesAndStringTable(src);
3885
3896
  const multipleNodeRefs = calcHasMultipleReferences(nodes);
3886
- const multiStringRefs = new Set([0]);
3897
+ const multiStringRefs = /* @__PURE__ */ new Set([0]);
3887
3898
  if (!builder.length) builder.addString("");
3888
3899
  walkNodes(nodes, 0, { after: processNode });
3889
3900
  const r = {
@@ -3917,7 +3928,7 @@ function optimizeNodesWithStringTable(src) {
3917
3928
  const prefixBytes = [charByte, ...childBytes];
3918
3929
  const prefixIdx = builder.addStringBytes(prefixBytes);
3919
3930
  const newNode = Uint32Array.from(childNode);
3920
- newNode[0] = prefixIdx << 9 | childHeader & ~NodeHeaderPrefixMask;
3931
+ newNode[0] = prefixIdx << 9 | childHeader & -1073741313;
3921
3932
  nodes[nodeIdx] = newNode;
3922
3933
  }
3923
3934
  }
@@ -4112,7 +4123,8 @@ var TrieBlobINode = class TrieBlobINode {
4112
4123
  entries() {
4113
4124
  if (this._entries) return this._entries;
4114
4125
  if (!this.hasChildren) return EMPTY_ENTRIES;
4115
- this._entries = this.getNodesEntries().map(([key, value]) => [key, new TrieBlobINode(this.trie, value)]);
4126
+ const entries = this.getNodesEntries();
4127
+ this._entries = entries.map(([key, value]) => [key, new TrieBlobINode(this.trie, value)]);
4116
4128
  return this._entries;
4117
4129
  }
4118
4130
  entryAt(keyIdx) {
@@ -4889,7 +4901,7 @@ var TrieBlobBuilder = class TrieBlobBuilder {
4889
4901
  }
4890
4902
  assert(this.nodes.length === 2);
4891
4903
  const eowNodeIndex = 1;
4892
- const eowShifted = eowNodeIndex << nodeChildRefShift;
4904
+ const eowShifted = 256;
4893
4905
  const nodes = this.nodes;
4894
4906
  const stack = [{
4895
4907
  nodeIdx: 0,
@@ -5124,7 +5136,7 @@ var TrieBlobBuilder = class TrieBlobBuilder {
5124
5136
  const NodeMaskEOW = 256;
5125
5137
  const tf = new TrieBlobBuilder(void 0, root);
5126
5138
  const IdxEOW = tf.IdxEOW;
5127
- const known = new Map([[root, 0]]);
5139
+ const known = /* @__PURE__ */ new Map([[root, 0]]);
5128
5140
  function resolveNode(n) {
5129
5141
  if (n.f && !n.c) return IdxEOW;
5130
5142
  const node = [n.f ? NodeMaskEOW : 0];
@@ -5184,7 +5196,7 @@ var TrieBlobBuilder = class TrieBlobBuilder {
5184
5196
  const NodeMaskEOW = 256;
5185
5197
  const tf = new TrieBlobBuilder(void 0, root);
5186
5198
  const IdxEOW = tf.IdxEOW;
5187
- const known = new Map([[root.id, 0]]);
5199
+ const known = /* @__PURE__ */ new Map([[root.id, 0]]);
5188
5200
  function resolveNode(n) {
5189
5201
  if (n.eow && !n.hasChildren()) return IdxEOW;
5190
5202
  const node = [n.eow ? NodeMaskEOW : 0];
@@ -5475,7 +5487,8 @@ var ITrieImpl = class ITrieImpl {
5475
5487
  static create(words, info) {
5476
5488
  const builder = new TrieBlobBuilder(info);
5477
5489
  builder.insert(words);
5478
- return new ITrieImpl(builder.build());
5490
+ const root = builder.build();
5491
+ return new ITrieImpl(root);
5479
5492
  }
5480
5493
  createFindOptions(options) {
5481
5494
  return createFindOptions$1(options);
@@ -6086,10 +6099,12 @@ var TrieNodeTrie = class TrieNodeTrie {
6086
6099
  return this._size ??= countNodes(this.root);
6087
6100
  }
6088
6101
  static createFromWords(words, options) {
6089
- return new TrieNodeTrie(createTrieRootFromList(words, options));
6102
+ const root = createTrieRootFromList(words, options);
6103
+ return new TrieNodeTrie(root);
6090
6104
  }
6091
6105
  static createFromWordsAndConsolidate(words, options) {
6092
- return new TrieNodeTrie(consolidate(createTrieRootFromList(words, options)));
6106
+ const root = createTrieRootFromList(words, options);
6107
+ return new TrieNodeTrie(consolidate(root));
6093
6108
  }
6094
6109
  };
6095
6110
  //#endregion
@@ -6424,7 +6439,7 @@ function convertToTrieRefNodes(root) {
6424
6439
  f: 1,
6425
6440
  c: void 0
6426
6441
  };
6427
- const tallies = new Map([[eow, 0]]);
6442
+ const tallies = /* @__PURE__ */ new Map([[eow, 0]]);
6428
6443
  let count = 0;
6429
6444
  const cached = /* @__PURE__ */ new Map();
6430
6445
  const rollupTally = /* @__PURE__ */ new Map();
@@ -6900,7 +6915,10 @@ ${INLINE_DATA_COMMENT_LINE}* `;
6900
6915
  return;
6901
6916
  }
6902
6917
  if (node.c) {
6903
- if (depth > 0 && depth <= 2) yield* emit(comment_begin + wordChars.slice(0, depth).map(escape).join("") + comment_end);
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
+ }
6904
6922
  cache.set(node, count++);
6905
6923
  const c = Object.entries(node.c).sort((a, b) => a[0] < b[0] ? -1 : 1);
6906
6924
  for (const [s, n] of c) {
@@ -7312,7 +7330,7 @@ var TrieNodeBuilder = class {
7312
7330
  };
7313
7331
  //#endregion
7314
7332
  //#region src/lib/io/importV3.ts
7315
- const characterMap = new Map([...new Map([
7333
+ const characterMap = new Map([.../* @__PURE__ */ new Map([
7316
7334
  ["\n", "\\n"],
7317
7335
  ["\r", "\\r"],
7318
7336
  ["\\", "\\\\"]
@@ -7424,7 +7442,7 @@ function parseStream(radix) {
7424
7442
  function parseIgnore(acc, _) {
7425
7443
  return acc;
7426
7444
  }
7427
- const parsers = new Map([
7445
+ const parsers = /* @__PURE__ */ new Map([
7428
7446
  ["$", parseEOW],
7429
7447
  ["<", parseBack],
7430
7448
  ["#", parseReference],
@@ -7498,7 +7516,7 @@ const insertSpaceCost = -1;
7498
7516
  const mapSubCost = opCosts.visuallySimilar;
7499
7517
  const maxCostScale = opCosts.wordLengthCostFactor;
7500
7518
  const discourageInsertCost = baseCost;
7501
- const setOfSeparators = new Set(["+", " "]);
7519
+ const setOfSeparators = /* @__PURE__ */ new Set(["+", " "]);
7502
7520
  function suggest(root, word, options = {}) {
7503
7521
  const opts = createSuggestionOptions(options);
7504
7522
  const collector = suggestionCollector(word, clean(opts));
@@ -7534,9 +7552,7 @@ function* genCompoundableSuggestions(root, word, options = {}) {
7534
7552
  case "number":
7535
7553
  costLimit = maxCost;
7536
7554
  break;
7537
- case "symbol":
7538
- stopNow = true;
7539
- break;
7555
+ case "symbol": stopNow = true;
7540
7556
  }
7541
7557
  }
7542
7558
  const a = 0;
@@ -8032,11 +8048,13 @@ var TrieBuilder = class {
8032
8048
  const n = this.transforms.get(node)?.get(s.join(""));
8033
8049
  if (n) return this.#tryCacheFrozen(n);
8034
8050
  }
8035
- if (!s.length) if (!node.c) return this._eow;
8036
- else {
8037
- node = this.#copyIfFrozen(node);
8038
- node.f = this._eow.f;
8039
- return node;
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
+ }
8040
8058
  }
8041
8059
  const head = s[0];
8042
8060
  const tail = s.slice(1);
@@ -8239,9 +8257,7 @@ function createDictionaryLineParserMapper(options) {
8239
8257
  case "no-generate-alternatives":
8240
8258
  stripCaseAndAccents = false;
8241
8259
  break;
8242
- case "generate-alternatives":
8243
- stripCaseAndAccents = true;
8244
- break;
8260
+ case "generate-alternatives": stripCaseAndAccents = true;
8245
8261
  }
8246
8262
  }
8247
8263
  return line.slice(0, idx).trim();
@@ -8531,7 +8547,7 @@ const specialCharacters = stringToCharSet([
8531
8547
  "0123456789",
8532
8548
  "`~!@#$%^&*()_-+=[]{};:'\"<>,./?\\|"
8533
8549
  ].join(""));
8534
- const specialCharacterMap = new Map([
8550
+ const specialCharacterMap = /* @__PURE__ */ new Map([
8535
8551
  ["\n", "\\n"],
8536
8552
  ["\r", "\\r"],
8537
8553
  ["\\", "\\\\"]
@@ -10961,7 +10977,7 @@ function parseAccents(cs, _editCost) {
10961
10977
  }
10962
10978
  function calcCostsForAccentedLetters(simpleMap, locale, costs) {
10963
10979
  const charactersWithAccents = [...pipeSync(splitMap(simpleMap), opMapSync((char) => caseForms(char, locale)), opFlattenSync(), opMapSync((char) => [...accentForms(char)]), opFilterSync((forms) => forms.length > 1))];
10964
- 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("|");
10965
10981
  const cost = costs.accentCosts;
10966
10982
  const costToReplaceAccent = !replaceAccentMap ? [] : [{
10967
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.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.0"
65
+ "@cspell/cspell-types": "10.1.0"
66
66
  },
67
67
  "devDependencies": {
68
- "@cspell/cspell-performance-monitor": "10.0.0",
69
- "@cspell/cspell-pipe": "10.0.0",
70
- "@cspell/dict-cpp": "^7.0.2",
71
- "@cspell/dict-en_us": "^4.4.33",
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": "6ddfd576b6bb554a7cb8dba1ab053a0b6ff8021f"
76
+ "gitHead": "401518c5e37c06fb406aedadb3fc7a1c27eca8e6"
77
77
  }