cspell-dictionary 6.25.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.
- package/dist/SpellingDictionary/FlagWordsDictionary.js +11 -7
- package/dist/SpellingDictionary/IgnoreWordsDictionary.js +16 -12
- package/dist/SpellingDictionary/SuggestDictionary.js +9 -4
- package/dist/SpellingDictionary/TyposDictionary.js +9 -4
- package/dist/SpellingDictionary/createInlineSpellingDictionary.js +12 -8
- package/dist/util/AutoResolve.d.ts +21 -0
- package/dist/util/AutoResolve.js +62 -0
- package/package.json +5 -5
|
@@ -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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
|
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.createSuggestDictionary = 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");
|
|
@@ -81,6 +82,7 @@ class SuggestDictionaryImpl {
|
|
|
81
82
|
if (!(word in this.typosDef))
|
|
82
83
|
return undefined;
|
|
83
84
|
const sug = this.typosDef[word];
|
|
85
|
+
const isPreferred = true;
|
|
84
86
|
if (!sug)
|
|
85
87
|
return [];
|
|
86
88
|
if (typeof sug === 'string') {
|
|
@@ -88,11 +90,11 @@ class SuggestDictionaryImpl {
|
|
|
88
90
|
{
|
|
89
91
|
word: sug,
|
|
90
92
|
cost: 1,
|
|
91
|
-
isPreferred
|
|
93
|
+
isPreferred,
|
|
92
94
|
},
|
|
93
95
|
];
|
|
94
96
|
}
|
|
95
|
-
return sug.map((word, index) => ({ word, cost: index + 1 }));
|
|
97
|
+
return sug.map((word, index) => ({ word, cost: index + 1, isPreferred }));
|
|
96
98
|
}
|
|
97
99
|
genSuggestions(collector) {
|
|
98
100
|
const sugs = this.suggest(collector.word);
|
|
@@ -105,6 +107,7 @@ class SuggestDictionaryImpl {
|
|
|
105
107
|
return [];
|
|
106
108
|
}
|
|
107
109
|
}
|
|
110
|
+
const createCache = (0, AutoResolve_1.createAutoResolveWeakCache)();
|
|
108
111
|
/**
|
|
109
112
|
* Create a dictionary where all words are to be forbidden.
|
|
110
113
|
* @param entries - list of Typos Entries
|
|
@@ -113,8 +116,10 @@ class SuggestDictionaryImpl {
|
|
|
113
116
|
* @returns
|
|
114
117
|
*/
|
|
115
118
|
function createSuggestDictionary(entries, name, source) {
|
|
116
|
-
|
|
117
|
-
|
|
119
|
+
return createCache.get(entries, () => {
|
|
120
|
+
const def = (0, Typos_1.processEntriesToTyposDef)(entries);
|
|
121
|
+
return new SuggestDictionaryImpl(name, source, def);
|
|
122
|
+
});
|
|
118
123
|
}
|
|
119
124
|
exports.createSuggestDictionary = createSuggestDictionary;
|
|
120
125
|
//# sourceMappingURL=SuggestDictionary.js.map
|
|
@@ -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
|
|
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
|
-
|
|
149
|
-
|
|
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,21 +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");
|
|
9
10
|
const SuggestDictionary_1 = require("./SuggestDictionary");
|
|
11
|
+
const cache = (0, AutoResolve_1.createAutoResolveWeakCache)();
|
|
10
12
|
function createInlineSpellingDictionary(inlineDict, source) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
});
|
|
19
23
|
}
|
|
20
24
|
exports.createInlineSpellingDictionary = createInlineSpellingDictionary;
|
|
21
25
|
//# sourceMappingURL=createInlineSpellingDictionary.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.
|
|
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.
|
|
47
|
-
"@cspell/cspell-types": "6.
|
|
48
|
-
"cspell-trie-lib": "6.
|
|
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": "
|
|
52
|
+
"gitHead": "a72f603f4f1afbe237f938b1a23d7cbe2a07d86f"
|
|
53
53
|
}
|