cspell-dictionary 6.24.0 → 6.26.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.
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.createFlagWordsDictionary = void 0;
27
27
  const sync_1 = require("@cspell/cspell-pipe/sync");
28
28
  const cspell_trie_lib_1 = require("cspell-trie-lib");
29
+ const AutoResolve_1 = require("../util/AutoResolve");
29
30
  const Defaults = __importStar(require("./defaults"));
30
31
  const SpellingDictionary_1 = require("./SpellingDictionary");
31
32
  const SpellingDictionaryFromTrie_1 = require("./SpellingDictionaryFromTrie");
@@ -119,6 +120,7 @@ class FlagWordsDictionary {
119
120
  return [];
120
121
  }
121
122
  }
123
+ const createCache = (0, AutoResolve_1.createAutoResolveWeakCache)();
122
124
  /**
123
125
  * Create a dictionary where all words are to be forbidden.
124
126
  * @param wordList - list of words
@@ -128,13 +130,15 @@ class FlagWordsDictionary {
128
130
  * @returns SpellingDictionary
129
131
  */
130
132
  function createFlagWordsDictionary(wordList, name, source) {
131
- const testSpecialCharacters = /[~*+]/;
132
- const { t: specialWords, f: typoWords } = bisect((0, cspell_trie_lib_1.parseDictionaryLines)(wordList, { stripCaseAndAccents: false }), (line) => testSpecialCharacters.test(line));
133
- const trieDict = specialWords.size ? buildTrieDict(specialWords, name, source) : undefined;
134
- const typosDict = (0, TyposDictionary_1.createTyposDictionary)(typoWords, name, source);
135
- if (!trieDict)
136
- return typosDict;
137
- return new FlagWordsDictionary(name, source, typosDict, trieDict);
133
+ return createCache.get(wordList, () => {
134
+ const testSpecialCharacters = /[~*+]/;
135
+ const { t: specialWords, f: typoWords } = bisect((0, cspell_trie_lib_1.parseDictionaryLines)(wordList, { stripCaseAndAccents: false }), (line) => testSpecialCharacters.test(line));
136
+ const trieDict = specialWords.size ? buildTrieDict(specialWords, name, source) : undefined;
137
+ const typosDict = (0, TyposDictionary_1.createTyposDictionary)(typoWords, name, source);
138
+ if (!trieDict)
139
+ return typosDict;
140
+ return new FlagWordsDictionary(name, source, typosDict, trieDict);
141
+ });
138
142
  }
139
143
  exports.createFlagWordsDictionary = createFlagWordsDictionary;
140
144
  const regExpCleanIgnore = /^(!!)+/;
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.createIgnoreWordsDictionary = void 0;
27
27
  const sync_1 = require("@cspell/cspell-pipe/sync");
28
28
  const cspell_trie_lib_1 = require("cspell-trie-lib");
29
+ const AutoResolve_1 = require("../util/AutoResolve");
29
30
  const createSpellingDictionary_1 = require("./createSpellingDictionary");
30
31
  const Defaults = __importStar(require("./defaults"));
31
32
  const NormalizeForm = 'NFC';
@@ -94,6 +95,7 @@ class IgnoreWordsDictionary {
94
95
  return [];
95
96
  }
96
97
  }
98
+ const createCache = (0, AutoResolve_1.createAutoResolveWeakCache)();
97
99
  /**
98
100
  * Create a dictionary where all words are to be ignored.
99
101
  * Ignored words override forbidden words.
@@ -103,18 +105,20 @@ class IgnoreWordsDictionary {
103
105
  * @returns
104
106
  */
105
107
  function createIgnoreWordsDictionary(wordList, name, source) {
106
- const testSpecialCharacters = /[*+]/;
107
- const words = [...(0, cspell_trie_lib_1.parseDictionaryLines)(wordList, { stripCaseAndAccents: true })].map((w) => w.normalize(NormalizeForm));
108
- const hasSpecial = words.findIndex((word) => testSpecialCharacters.test(word)) >= 0;
109
- if (hasSpecial) {
110
- return (0, createSpellingDictionary_1.createSpellingDictionary)(words, name, source, {
111
- caseSensitive: true,
112
- noSuggest: true,
113
- weightMap: undefined,
114
- supportNonStrictSearches: true,
115
- });
116
- }
117
- return new IgnoreWordsDictionary(name, source, words);
108
+ return createCache.get(wordList, () => {
109
+ const testSpecialCharacters = /[*+]/;
110
+ const words = [...(0, cspell_trie_lib_1.parseDictionaryLines)(wordList, { stripCaseAndAccents: true })].map((w) => w.normalize(NormalizeForm));
111
+ const hasSpecial = words.findIndex((word) => testSpecialCharacters.test(word)) >= 0;
112
+ if (hasSpecial) {
113
+ return (0, createSpellingDictionary_1.createSpellingDictionary)(words, name, source, {
114
+ caseSensitive: true,
115
+ noSuggest: true,
116
+ weightMap: undefined,
117
+ supportNonStrictSearches: true,
118
+ });
119
+ }
120
+ return new IgnoreWordsDictionary(name, source, words);
121
+ });
118
122
  }
119
123
  exports.createIgnoreWordsDictionary = createIgnoreWordsDictionary;
120
124
  //# sourceMappingURL=IgnoreWordsDictionary.js.map
@@ -0,0 +1,20 @@
1
+ import type { IgnoreCaseOption, SpellingDictionary } from './SpellingDictionary';
2
+ import { type TypoEntry, type TyposDef } from './Typos';
3
+ export interface SuggestDictionary extends SpellingDictionary {
4
+ /**
5
+ * Determine if the word can appear in a list of suggestions.
6
+ * @param word - word
7
+ * @param ignoreCaseAndAccents - ignore case.
8
+ * @returns true if a word is suggested, otherwise false.
9
+ */
10
+ isSuggestedWord(word: string, ignoreCaseAndAccents?: IgnoreCaseOption): boolean;
11
+ }
12
+ /**
13
+ * Create a dictionary where all words are to be forbidden.
14
+ * @param entries - list of Typos Entries
15
+ * @param name - name of dictionary
16
+ * @param source - source
17
+ * @returns
18
+ */
19
+ export declare function createSuggestDictionary(entries: readonly string[] | TyposDef | Iterable<TypoEntry>, name: string, source: string): SuggestDictionary;
20
+ //# sourceMappingURL=SuggestDictionary.d.ts.map
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.createSuggestDictionary = void 0;
27
+ const sync_1 = require("@cspell/cspell-pipe/sync");
28
+ const AutoResolve_1 = require("../util/AutoResolve");
29
+ const textMappers_1 = require("../util/textMappers");
30
+ const defaults = __importStar(require("./defaults"));
31
+ const Typos_1 = require("./Typos");
32
+ const util_1 = require("./Typos/util");
33
+ class SuggestDictionaryImpl {
34
+ constructor(name, source, typosDef) {
35
+ this.name = name;
36
+ this.source = source;
37
+ this.typosDef = typosDef;
38
+ this.containsNoSuggestWords = false;
39
+ this.options = {};
40
+ this.type = 'suggest';
41
+ this.isDictionaryCaseSensitive = true;
42
+ this.size = Object.keys(typosDef).length;
43
+ this.suggestions = (0, util_1.extractAllSuggestions)(typosDef);
44
+ this.suggestionsLower = new Set((0, sync_1.pipe)(this.suggestions, textMappers_1.mapperRemoveCaseAndAccents));
45
+ }
46
+ /**
47
+ * A Forbidden word list does not "have" valid words.
48
+ * Therefore it always returns false.
49
+ * @param _word - the word
50
+ * @param _options - options
51
+ * @returns always false
52
+ */
53
+ has(_word, _options) {
54
+ return false;
55
+ }
56
+ /** A more detailed search for a word, might take longer than `has` */
57
+ find(_word, _options) {
58
+ return undefined;
59
+ }
60
+ isForbidden(_word, _ignoreCaseAndAccents) {
61
+ return false;
62
+ }
63
+ isNoSuggestWord(_word, _options) {
64
+ return false;
65
+ }
66
+ /**
67
+ * Determine if the word can appear in a list of suggestions.
68
+ * @param word - word
69
+ * @param ignoreCaseAndAccents - ignore case.
70
+ * @returns true if a word is suggested, otherwise false.
71
+ */
72
+ isSuggestedWord(word, ignoreCaseAndAccents = defaults.isForbiddenIgnoreCaseAndAccents) {
73
+ if (this.suggestions.has(word))
74
+ return true;
75
+ const lcWord = word.toLowerCase();
76
+ return ignoreCaseAndAccents && (this.suggestions.has(lcWord) || this.suggestionsLower.has(lcWord));
77
+ }
78
+ suggest(word) {
79
+ return this._suggest(word) || this._suggest(word.toLowerCase()) || [];
80
+ }
81
+ _suggest(word) {
82
+ if (!(word in this.typosDef))
83
+ return undefined;
84
+ const sug = this.typosDef[word];
85
+ const isPreferred = true;
86
+ if (!sug)
87
+ return [];
88
+ if (typeof sug === 'string') {
89
+ return [
90
+ {
91
+ word: sug,
92
+ cost: 1,
93
+ isPreferred,
94
+ },
95
+ ];
96
+ }
97
+ return sug.map((word, index) => ({ word, cost: index + 1, isPreferred }));
98
+ }
99
+ genSuggestions(collector) {
100
+ const sugs = this.suggest(collector.word);
101
+ sugs.forEach((result) => collector.add(result));
102
+ }
103
+ mapWord(word) {
104
+ return word;
105
+ }
106
+ getErrors() {
107
+ return [];
108
+ }
109
+ }
110
+ const createCache = (0, AutoResolve_1.createAutoResolveWeakCache)();
111
+ /**
112
+ * Create a dictionary where all words are to be forbidden.
113
+ * @param entries - list of Typos Entries
114
+ * @param name - name of dictionary
115
+ * @param source - source
116
+ * @returns
117
+ */
118
+ function createSuggestDictionary(entries, name, source) {
119
+ return createCache.get(entries, () => {
120
+ const def = (0, Typos_1.processEntriesToTyposDef)(entries);
121
+ return new SuggestDictionaryImpl(name, source, def);
122
+ });
123
+ }
124
+ exports.createSuggestDictionary = createSuggestDictionary;
125
+ //# sourceMappingURL=SuggestDictionary.js.map
@@ -2,6 +2,23 @@ import type { TypoEntry, TyposDef } from './typos';
2
2
  export declare function createTyposDefFromEntries(entries: Iterable<TypoEntry>): TyposDef;
3
3
  export declare function sanitizeIntoTypoDef(dirtyDef: TyposDef | Record<string, unknown> | unknown): TyposDef | undefined;
4
4
  /**
5
+ * Parse Typos Entries
6
+ *
7
+ * Format:
8
+ * - `word:suggestion`
9
+ * - `word->suggestion`
10
+ * - `word: first, second, third suggestions`
11
+ *
12
+ * Note:
13
+ * ```plaintext
14
+ * yellow:blue, green
15
+ * ```
16
+ * Is the same as multiple entries with the same key and different suggestions.
17
+ * ```plaintext
18
+ * yellow:blue
19
+ * yellow:green
20
+ * ```
21
+ *
5
22
  * Used to process entries found in a `cspell.json` file.
6
23
  * @param entries - entries to process
7
24
  * @returns a TyposDef
@@ -62,6 +62,23 @@ function sanitizeIntoTypoDef(dirtyDef) {
62
62
  }
63
63
  exports.sanitizeIntoTypoDef = sanitizeIntoTypoDef;
64
64
  /**
65
+ * Parse Typos Entries
66
+ *
67
+ * Format:
68
+ * - `word:suggestion`
69
+ * - `word->suggestion`
70
+ * - `word: first, second, third suggestions`
71
+ *
72
+ * Note:
73
+ * ```plaintext
74
+ * yellow:blue, green
75
+ * ```
76
+ * Is the same as multiple entries with the same key and different suggestions.
77
+ * ```plaintext
78
+ * yellow:blue
79
+ * yellow:green
80
+ * ```
81
+ *
65
82
  * Used to process entries found in a `cspell.json` file.
66
83
  * @param entries - entries to process
67
84
  * @returns a TyposDef
@@ -1,4 +1,12 @@
1
1
  import type { TypoEntry, TyposDef, TyposDefKey, TyposDefValue } from './typos';
2
+ export declare function mergeDefEntry(targetDef: TyposDef, key: string, value: TyposDefValue): TyposDef;
3
+ /**
4
+ * Merge in place the entries `fromDef` into `targetDef`
5
+ * @param targetDef - the target
6
+ * @param fromDef - the source
7
+ * @returns the target
8
+ */
9
+ export declare function mergeDef(targetDef: TyposDef, fromDef: TyposDef): TyposDef;
2
10
  /**
3
11
  * Append an entry to a TyposDef.
4
12
  * @param def - modified in place
@@ -1,7 +1,47 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractIgnoreValues = exports.extractAllSuggestions = exports.createTyposDef = exports.appendToDef = void 0;
3
+ exports.extractIgnoreValues = exports.extractAllSuggestions = exports.createTyposDef = exports.appendToDef = exports.mergeDef = exports.mergeDefEntry = void 0;
4
4
  const sync_1 = require("@cspell/cspell-pipe/sync");
5
+ function normalizeTyposDefValue(value) {
6
+ if (!value)
7
+ return false;
8
+ if (typeof value === 'string')
9
+ return value;
10
+ const unique = [...new Set(value)];
11
+ return unique.length > 1 ? unique : unique.length === 1 ? unique[0] : false;
12
+ }
13
+ function mergeDefEntry(targetDef, key, value) {
14
+ const curValue = targetDef[key];
15
+ if (!curValue) {
16
+ targetDef[key] = normalizeTyposDefValue(value);
17
+ return targetDef;
18
+ }
19
+ if (!value)
20
+ return targetDef;
21
+ const newValue = Array.isArray(curValue) ? curValue : [curValue];
22
+ if (Array.isArray(value)) {
23
+ newValue.push(...value);
24
+ }
25
+ else {
26
+ newValue.push(value);
27
+ }
28
+ targetDef[key] = normalizeTyposDefValue(newValue);
29
+ return targetDef;
30
+ }
31
+ exports.mergeDefEntry = mergeDefEntry;
32
+ /**
33
+ * Merge in place the entries `fromDef` into `targetDef`
34
+ * @param targetDef - the target
35
+ * @param fromDef - the source
36
+ * @returns the target
37
+ */
38
+ function mergeDef(targetDef, fromDef) {
39
+ for (const key of Object.keys(fromDef)) {
40
+ mergeDefEntry(targetDef, key, fromDef[key]);
41
+ }
42
+ return targetDef;
43
+ }
44
+ exports.mergeDef = mergeDef;
5
45
  /**
6
46
  * Append an entry to a TyposDef.
7
47
  * @param def - modified in place
@@ -12,7 +52,9 @@ function appendToDef(def, entry) {
12
52
  if (!entry)
13
53
  return def;
14
54
  if (typeof entry === 'string') {
15
- def[entry] = false;
55
+ if (!def[entry]) {
56
+ def[entry] = false;
57
+ }
16
58
  return def;
17
59
  }
18
60
  if (Array.isArray(entry)) {
@@ -20,11 +62,9 @@ function appendToDef(def, entry) {
20
62
  if (!key)
21
63
  return def;
22
64
  const s = sugs.map((s) => s.trim()).filter((s) => !!s);
23
- def[key] = !s.length ? false : s.length === 1 ? s[0] : s;
24
- return def;
65
+ return mergeDefEntry(def, key, s);
25
66
  }
26
- Object.assign(def, entry);
27
- return def;
67
+ return mergeDef(def, entry);
28
68
  }
29
69
  exports.appendToDef = appendToDef;
30
70
  function createTyposDef(entries) {
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.createTyposDictionary = void 0;
27
27
  const sync_1 = require("@cspell/cspell-pipe/sync");
28
+ const AutoResolve_1 = require("../util/AutoResolve");
28
29
  const textMappers_1 = require("../util/textMappers");
29
30
  const defaults = __importStar(require("./defaults"));
30
31
  const Typos_1 = require("./Typos");
@@ -113,6 +114,7 @@ class TyposDictionaryImpl {
113
114
  if (!(word in this.typosDef))
114
115
  return undefined;
115
116
  const sug = this.typosDef[word];
117
+ const isPreferred = true;
116
118
  if (!sug)
117
119
  return [];
118
120
  if (typeof sug === 'string') {
@@ -120,11 +122,11 @@ class TyposDictionaryImpl {
120
122
  {
121
123
  word: sug,
122
124
  cost: 1,
123
- isPreferred: true,
125
+ isPreferred,
124
126
  },
125
127
  ];
126
128
  }
127
- return sug.map((word, index) => ({ word, cost: index + 1 }));
129
+ return sug.map((word, index) => ({ word, cost: index + 1, isPreferred }));
128
130
  }
129
131
  genSuggestions(collector) {
130
132
  const sugs = this.suggest(collector.word);
@@ -137,6 +139,7 @@ class TyposDictionaryImpl {
137
139
  return [];
138
140
  }
139
141
  }
142
+ const createCache = (0, AutoResolve_1.createAutoResolveWeakCache)();
140
143
  /**
141
144
  * Create a dictionary where all words are to be forbidden.
142
145
  * @param entries - list of Typos Entries
@@ -145,8 +148,10 @@ class TyposDictionaryImpl {
145
148
  * @returns
146
149
  */
147
150
  function createTyposDictionary(entries, name, source) {
148
- const def = (0, Typos_1.processEntriesToTyposDef)(entries);
149
- return new TyposDictionaryImpl(name, source, def);
151
+ return createCache.get(entries, () => {
152
+ const def = (0, Typos_1.processEntriesToTyposDef)(entries);
153
+ return new TyposDictionaryImpl(name, source, def);
154
+ });
150
155
  }
151
156
  exports.createTyposDictionary = createTyposDictionary;
152
157
  //# sourceMappingURL=TyposDictionary.js.map
@@ -1,19 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createInlineSpellingDictionary = void 0;
4
+ const AutoResolve_1 = require("../util/AutoResolve");
4
5
  const util_1 = require("../util/util");
5
6
  const createSpellingDictionary_1 = require("./createSpellingDictionary");
6
7
  const FlagWordsDictionary_1 = require("./FlagWordsDictionary");
7
8
  const IgnoreWordsDictionary_1 = require("./IgnoreWordsDictionary");
8
9
  const SpellingDictionaryCollection_1 = require("./SpellingDictionaryCollection");
10
+ const SuggestDictionary_1 = require("./SuggestDictionary");
11
+ const cache = (0, AutoResolve_1.createAutoResolveWeakCache)();
9
12
  function createInlineSpellingDictionary(inlineDict, source) {
10
- const { words, flagWords, ignoreWords, name } = inlineDict;
11
- const dictSources = [
12
- words && (0, createSpellingDictionary_1.createSpellingDictionary)(words, name + '-words', source, inlineDict),
13
- flagWords && (0, FlagWordsDictionary_1.createFlagWordsDictionary)(flagWords, name + '-flag-words', source),
14
- ignoreWords && (0, IgnoreWordsDictionary_1.createIgnoreWordsDictionary)(ignoreWords, name + '-ignore-words', source),
15
- ].filter(util_1.isDefined);
16
- return (0, SpellingDictionaryCollection_1.createCollection)(dictSources, name);
13
+ return cache.get(inlineDict, () => {
14
+ const { words, flagWords, ignoreWords, suggestWords, name } = inlineDict;
15
+ const dictSources = [
16
+ words && (0, createSpellingDictionary_1.createSpellingDictionary)(words, name + '-words', source, inlineDict),
17
+ flagWords && (0, FlagWordsDictionary_1.createFlagWordsDictionary)(flagWords, name + '-flag-words', source),
18
+ ignoreWords && (0, IgnoreWordsDictionary_1.createIgnoreWordsDictionary)(ignoreWords, name + '-ignore-words', source),
19
+ suggestWords && (0, SuggestDictionary_1.createSuggestDictionary)(suggestWords, name + '-suggest', source),
20
+ ].filter(util_1.isDefined);
21
+ return (0, SpellingDictionaryCollection_1.createCollection)(dictSources, name);
22
+ });
17
23
  }
18
24
  exports.createInlineSpellingDictionary = createInlineSpellingDictionary;
19
25
  //# sourceMappingURL=createInlineSpellingDictionary.js.map
@@ -6,5 +6,6 @@ export { createIgnoreWordsDictionary } from './IgnoreWordsDictionary';
6
6
  export type { DictionaryDefinitionInline, FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary';
7
7
  export { createCollection, SpellingDictionaryCollection } from './SpellingDictionaryCollection';
8
8
  export { createSpellingDictionaryFromTrieFile } from './SpellingDictionaryFromTrie';
9
+ export { createSuggestDictionary } from './SuggestDictionary';
9
10
  export { createTyposDictionary } from './TyposDictionary';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTyposDictionary = exports.createSpellingDictionaryFromTrieFile = exports.createCollection = exports.createIgnoreWordsDictionary = exports.createForbiddenWordsDictionary = exports.createFlagWordsDictionary = exports.createSpellingDictionary = exports.createFailedToLoadDictionary = exports.createInlineSpellingDictionary = exports.createCachingDictionary = void 0;
3
+ exports.createTyposDictionary = exports.createSuggestDictionary = exports.createSpellingDictionaryFromTrieFile = exports.createCollection = exports.createIgnoreWordsDictionary = exports.createForbiddenWordsDictionary = exports.createFlagWordsDictionary = exports.createSpellingDictionary = exports.createFailedToLoadDictionary = exports.createInlineSpellingDictionary = exports.createCachingDictionary = void 0;
4
4
  var CachingDictionary_1 = require("./CachingDictionary");
5
5
  Object.defineProperty(exports, "createCachingDictionary", { enumerable: true, get: function () { return CachingDictionary_1.createCachingDictionary; } });
6
6
  var createInlineSpellingDictionary_1 = require("./createInlineSpellingDictionary");
@@ -17,6 +17,8 @@ var SpellingDictionaryCollection_1 = require("./SpellingDictionaryCollection");
17
17
  Object.defineProperty(exports, "createCollection", { enumerable: true, get: function () { return SpellingDictionaryCollection_1.createCollection; } });
18
18
  var SpellingDictionaryFromTrie_1 = require("./SpellingDictionaryFromTrie");
19
19
  Object.defineProperty(exports, "createSpellingDictionaryFromTrieFile", { enumerable: true, get: function () { return SpellingDictionaryFromTrie_1.createSpellingDictionaryFromTrieFile; } });
20
+ var SuggestDictionary_1 = require("./SuggestDictionary");
21
+ Object.defineProperty(exports, "createSuggestDictionary", { enumerable: true, get: function () { return SuggestDictionary_1.createSuggestDictionary; } });
20
22
  var TyposDictionary_1 = require("./TyposDictionary");
21
23
  Object.defineProperty(exports, "createTyposDictionary", { enumerable: true, get: function () { return TyposDictionary_1.createTyposDictionary; } });
22
24
  //# sourceMappingURL=index.js.map
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export type { CachingDictionary, FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryCollection, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary';
2
- export { createCachingDictionary, createCollection, createFailedToLoadDictionary, createFlagWordsDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createInlineSpellingDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, } from './SpellingDictionary';
2
+ export { createCachingDictionary, createCollection, createFailedToLoadDictionary, createFlagWordsDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createInlineSpellingDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, createSuggestDictionary, } from './SpellingDictionary';
3
3
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSpellingDictionaryFromTrieFile = exports.createSpellingDictionary = exports.createInlineSpellingDictionary = exports.createIgnoreWordsDictionary = exports.createForbiddenWordsDictionary = exports.createFlagWordsDictionary = exports.createFailedToLoadDictionary = exports.createCollection = exports.createCachingDictionary = void 0;
3
+ exports.createSuggestDictionary = exports.createSpellingDictionaryFromTrieFile = exports.createSpellingDictionary = exports.createInlineSpellingDictionary = exports.createIgnoreWordsDictionary = exports.createForbiddenWordsDictionary = exports.createFlagWordsDictionary = exports.createFailedToLoadDictionary = exports.createCollection = exports.createCachingDictionary = void 0;
4
4
  var SpellingDictionary_1 = require("./SpellingDictionary");
5
5
  Object.defineProperty(exports, "createCachingDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createCachingDictionary; } });
6
6
  Object.defineProperty(exports, "createCollection", { enumerable: true, get: function () { return SpellingDictionary_1.createCollection; } });
@@ -11,4 +11,5 @@ Object.defineProperty(exports, "createIgnoreWordsDictionary", { enumerable: true
11
11
  Object.defineProperty(exports, "createInlineSpellingDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createInlineSpellingDictionary; } });
12
12
  Object.defineProperty(exports, "createSpellingDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createSpellingDictionary; } });
13
13
  Object.defineProperty(exports, "createSpellingDictionaryFromTrieFile", { enumerable: true, get: function () { return SpellingDictionary_1.createSpellingDictionaryFromTrieFile; } });
14
+ Object.defineProperty(exports, "createSuggestDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createSuggestDictionary; } });
14
15
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,21 @@
1
+ export declare function autoResolve<K, V>(map: Map<K, V>, key: K, resolve: (k: K) => V): V;
2
+ export declare class AutoResolveCache<K, V> {
3
+ readonly map: Map<K, V>;
4
+ get(k: K): V | undefined;
5
+ get(k: K, resolve: (k: K) => V): V;
6
+ get(k: K, resolve?: (k: K) => V): V | undefined;
7
+ has(k: K): boolean;
8
+ set(k: K, v: V): this;
9
+ }
10
+ export declare function createAutoResolveCache<K, V>(): AutoResolveCache<K, V>;
11
+ export declare function autoResolveWeak<K extends object, V>(map: WeakMap<K, V>, key: K, resolve: (k: K) => V): V;
12
+ export declare class AutoResolveWeakCache<K extends object, V> {
13
+ readonly map: WeakMap<K, V>;
14
+ get(k: K): V | undefined;
15
+ get(k: K, resolve: (k: K) => V): V;
16
+ get(k: K, resolve?: (k: K) => V): V | undefined;
17
+ has(k: K): boolean;
18
+ set(k: K, v: V): this;
19
+ }
20
+ export declare function createAutoResolveWeakCache<K extends object, V>(): AutoResolveWeakCache<K, V>;
21
+ //# sourceMappingURL=AutoResolve.d.ts.map
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAutoResolveWeakCache = exports.AutoResolveWeakCache = exports.autoResolveWeak = exports.createAutoResolveCache = exports.AutoResolveCache = exports.autoResolve = void 0;
4
+ function autoResolve(map, key, resolve) {
5
+ const found = map.get(key);
6
+ if (found !== undefined || map.has(key))
7
+ return found;
8
+ const value = resolve(key);
9
+ map.set(key, value);
10
+ return value;
11
+ }
12
+ exports.autoResolve = autoResolve;
13
+ class AutoResolveCache {
14
+ constructor() {
15
+ this.map = new Map();
16
+ }
17
+ get(k, resolve) {
18
+ return resolve ? autoResolve(this.map, k, resolve) : this.map.get(k);
19
+ }
20
+ has(k) {
21
+ return this.map.has(k);
22
+ }
23
+ set(k, v) {
24
+ this.map.set(k, v);
25
+ return this;
26
+ }
27
+ }
28
+ exports.AutoResolveCache = AutoResolveCache;
29
+ function createAutoResolveCache() {
30
+ return new AutoResolveCache();
31
+ }
32
+ exports.createAutoResolveCache = createAutoResolveCache;
33
+ function autoResolveWeak(map, key, resolve) {
34
+ const found = map.get(key);
35
+ if (found !== undefined || map.has(key))
36
+ return found;
37
+ const value = resolve(key);
38
+ map.set(key, value);
39
+ return value;
40
+ }
41
+ exports.autoResolveWeak = autoResolveWeak;
42
+ class AutoResolveWeakCache {
43
+ constructor() {
44
+ this.map = new WeakMap();
45
+ }
46
+ get(k, resolve) {
47
+ return resolve ? autoResolveWeak(this.map, k, resolve) : this.map.get(k);
48
+ }
49
+ has(k) {
50
+ return this.map.has(k);
51
+ }
52
+ set(k, v) {
53
+ this.map.set(k, v);
54
+ return this;
55
+ }
56
+ }
57
+ exports.AutoResolveWeakCache = AutoResolveWeakCache;
58
+ function createAutoResolveWeakCache() {
59
+ return new AutoResolveWeakCache();
60
+ }
61
+ exports.createAutoResolveWeakCache = createAutoResolveWeakCache;
62
+ //# sourceMappingURL=AutoResolve.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell-dictionary",
3
- "version": "6.24.0",
3
+ "version": "6.26.0",
4
4
  "description": "A spelling dictionary library useful for checking words and getting suggestions.",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -43,11 +43,11 @@
43
43
  "ts-jest": "^29.0.5"
44
44
  },
45
45
  "dependencies": {
46
- "@cspell/cspell-pipe": "6.24.0",
47
- "@cspell/cspell-types": "6.24.0",
48
- "cspell-trie-lib": "6.24.0",
46
+ "@cspell/cspell-pipe": "6.26.0",
47
+ "@cspell/cspell-types": "6.26.0",
48
+ "cspell-trie-lib": "6.26.0",
49
49
  "fast-equals": "^4.0.3",
50
50
  "gensequence": "^4.0.3"
51
51
  },
52
- "gitHead": "0d1e8bf9426cd0bfb814df4f61da12d8aee57ddd"
52
+ "gitHead": "a72f603f4f1afbe237f938b1a23d7cbe2a07d86f"
53
53
  }