cspell-trie-lib 6.29.2 → 6.30.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.
@@ -75,10 +75,12 @@ function suggestionCollector(wordToMatch, options) {
75
75
  }
76
76
  }
77
77
  function adjustCost(sug) {
78
+ if (sug.isPreferred)
79
+ return sug;
78
80
  const words = sug.word.split(regexSeparator);
79
81
  const extraCost = words.map((w) => wordLengthCost[w.length] || 0).reduce((a, b) => a + b, 0) +
80
82
  (words.length - 1) * EXTRA_WORD_COST;
81
- return { word: sug.word, cost: sug.cost + extraCost, isPreferred: sug.isPreferred };
83
+ return { word: sug.word, cost: sug.cost + extraCost };
82
84
  }
83
85
  function collectSuggestion(suggestion) {
84
86
  const { word, cost, isPreferred } = adjustCost(suggestion);
@@ -146,9 +148,9 @@ function suggestionCollector(wordToMatch, options) {
146
148
  const nWordToMatch = wordToMatch.normalize(NF);
147
149
  const rawValues = [...sugs.values()];
148
150
  const values = weightMap
149
- ? rawValues.map(({ word, isPreferred }) => ({
151
+ ? rawValues.map(({ word, cost, isPreferred }) => ({
150
152
  word,
151
- cost: (0, index_js_1.editDistanceWeighted)(nWordToMatch, word.normalize(NF), weightMap, 110),
153
+ cost: isPreferred ? cost : (0, index_js_1.editDistanceWeighted)(nWordToMatch, word.normalize(NF), weightMap, 110),
152
154
  isPreferred,
153
155
  }))
154
156
  : rawValues;
@@ -71,10 +71,12 @@ export function suggestionCollector(wordToMatch, options) {
71
71
  }
72
72
  }
73
73
  function adjustCost(sug) {
74
+ if (sug.isPreferred)
75
+ return sug;
74
76
  const words = sug.word.split(regexSeparator);
75
77
  const extraCost = words.map((w) => wordLengthCost[w.length] || 0).reduce((a, b) => a + b, 0) +
76
78
  (words.length - 1) * EXTRA_WORD_COST;
77
- return { word: sug.word, cost: sug.cost + extraCost, isPreferred: sug.isPreferred };
79
+ return { word: sug.word, cost: sug.cost + extraCost };
78
80
  }
79
81
  function collectSuggestion(suggestion) {
80
82
  const { word, cost, isPreferred } = adjustCost(suggestion);
@@ -142,9 +144,9 @@ export function suggestionCollector(wordToMatch, options) {
142
144
  const nWordToMatch = wordToMatch.normalize(NF);
143
145
  const rawValues = [...sugs.values()];
144
146
  const values = weightMap
145
- ? rawValues.map(({ word, isPreferred }) => ({
147
+ ? rawValues.map(({ word, cost, isPreferred }) => ({
146
148
  word,
147
- cost: editDistanceWeighted(nWordToMatch, word.normalize(NF), weightMap, 110),
149
+ cost: isPreferred ? cost : editDistanceWeighted(nWordToMatch, word.normalize(NF), weightMap, 110),
148
150
  isPreferred,
149
151
  }))
150
152
  : rawValues;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell-trie-lib",
3
- "version": "6.29.2",
3
+ "version": "6.30.0",
4
4
  "description": "Trie Data Structure to support cspell.",
5
5
  "type": "commonjs",
6
6
  "main": "dist/cjs/index.js",
@@ -50,8 +50,8 @@
50
50
  },
51
51
  "homepage": "https://github.com/streetsidesoftware/cspell#readme",
52
52
  "dependencies": {
53
- "@cspell/cspell-pipe": "6.29.2",
54
- "@cspell/cspell-types": "6.29.2",
53
+ "@cspell/cspell-pipe": "6.30.0",
54
+ "@cspell/cspell-types": "6.30.0",
55
55
  "gensequence": "^5.0.2"
56
56
  },
57
57
  "engines": {
@@ -61,5 +61,5 @@
61
61
  "@cspell/dict-en_us": "^3.0.0",
62
62
  "@cspell/dict-es-es": "^2.2.4"
63
63
  },
64
- "gitHead": "fae497508ec03795dfe0e0b70ea80cdf3d7be5a5"
64
+ "gitHead": "9af8c211fdeeb58e2d7a2be0e72405a23fe954cc"
65
65
  }