cspell-dictionary 6.28.0 → 6.29.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 → cjs/SpellingDictionary}/CachingDictionary.d.ts +3 -3
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/CachingDictionary.js +9 -9
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/FlagWordsDictionary.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/FlagWordsDictionary.js +11 -11
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/IgnoreWordsDictionary.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/IgnoreWordsDictionary.js +5 -5
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryCollection.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryCollection.js +12 -12
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryFromTrie.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryFromTrie.js +16 -16
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryMethods.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryMethods.js +5 -5
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SuggestDictionary.d.ts +2 -2
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SuggestDictionary.js +9 -9
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Terms/index.d.ts +1 -1
- package/dist/cjs/SpellingDictionary/Typos/index.d.ts +4 -0
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/index.js +7 -7
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/typos.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/typosParser.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/typosParser.js +6 -6
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/util.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/TyposDictionary.d.ts +2 -2
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/TyposDictionary.js +10 -10
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/createInlineSpellingDictionary.d.ts +1 -1
- package/dist/cjs/SpellingDictionary/createInlineSpellingDictionary.js +25 -0
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/createSpellingDictionary.d.ts +2 -2
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/createSpellingDictionary.js +9 -9
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/index.d.ts +10 -10
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/index.js +20 -20
- package/dist/{index.d.ts → cjs/index.d.ts} +2 -2
- package/dist/{index.js → cjs/index.js} +11 -11
- package/dist/{util → cjs/util}/clean.d.ts +1 -1
- package/dist/{util → cjs/util}/repMap.js +4 -4
- package/dist/{util → cjs/util}/textMappers.js +2 -2
- package/dist/esm/SpellingDictionary/CachingDictionary.d.mts +30 -0
- package/dist/esm/SpellingDictionary/CachingDictionary.mjs +45 -0
- package/dist/esm/SpellingDictionary/FlagWordsDictionary.d.mts +11 -0
- package/dist/esm/SpellingDictionary/FlagWordsDictionary.mjs +134 -0
- package/dist/esm/SpellingDictionary/IgnoreWordsDictionary.d.mts +11 -0
- package/dist/esm/SpellingDictionary/IgnoreWordsDictionary.mjs +96 -0
- package/dist/esm/SpellingDictionary/SpellingDictionary.d.mts +150 -0
- package/dist/esm/SpellingDictionary/SpellingDictionary.mjs +4 -0
- package/dist/esm/SpellingDictionary/SpellingDictionaryCollection.d.mts +16 -0
- package/dist/esm/SpellingDictionary/SpellingDictionaryCollection.mjs +111 -0
- package/dist/esm/SpellingDictionary/SpellingDictionaryFromTrie.d.mts +50 -0
- package/dist/esm/SpellingDictionary/SpellingDictionaryFromTrie.mjs +172 -0
- package/dist/esm/SpellingDictionary/SpellingDictionaryMethods.d.mts +26 -0
- package/dist/esm/SpellingDictionary/SpellingDictionaryMethods.mjs +96 -0
- package/dist/esm/SpellingDictionary/SuggestDictionary.d.mts +20 -0
- package/dist/esm/SpellingDictionary/SuggestDictionary.mjs +97 -0
- package/dist/esm/SpellingDictionary/Terms/index.d.mts +2 -0
- package/dist/esm/SpellingDictionary/Terms/index.mjs +1 -0
- package/dist/esm/SpellingDictionary/Terms/terms.d.mts +12 -0
- package/dist/esm/SpellingDictionary/Terms/terms.mjs +1 -0
- package/dist/esm/SpellingDictionary/Typos/index.d.mts +4 -0
- package/dist/esm/SpellingDictionary/Typos/index.mjs +2 -0
- package/dist/esm/SpellingDictionary/Typos/typos.d.mts +18 -0
- package/dist/esm/SpellingDictionary/Typos/typos.mjs +1 -0
- package/dist/esm/SpellingDictionary/Typos/typosParser.d.mts +34 -0
- package/dist/esm/SpellingDictionary/Typos/typosParser.mjs +131 -0
- package/dist/esm/SpellingDictionary/Typos/util.d.mts +31 -0
- package/dist/esm/SpellingDictionary/Typos/util.mjs +105 -0
- package/dist/esm/SpellingDictionary/TyposDictionary.d.mts +21 -0
- package/dist/esm/SpellingDictionary/TyposDictionary.mjs +129 -0
- package/dist/esm/SpellingDictionary/createInlineSpellingDictionary.d.mts +3 -0
- package/dist/esm/SpellingDictionary/createInlineSpellingDictionary.mjs +20 -0
- package/dist/esm/SpellingDictionary/createSpellingDictionary.d.mts +23 -0
- package/dist/esm/SpellingDictionary/createSpellingDictionary.mjs +68 -0
- package/dist/esm/SpellingDictionary/defaults.d.mts +3 -0
- package/dist/esm/SpellingDictionary/defaults.mjs +2 -0
- package/dist/esm/SpellingDictionary/index.d.mts +11 -0
- package/dist/esm/SpellingDictionary/index.mjs +9 -0
- package/dist/esm/index.d.mts +3 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/util/AutoCache.d.mts +25 -0
- package/dist/esm/util/AutoCache.mjs +67 -0
- package/dist/esm/util/AutoResolve.d.mts +21 -0
- package/dist/esm/util/AutoResolve.mjs +52 -0
- package/dist/esm/util/IterableLike.d.mts +4 -0
- package/dist/esm/util/IterableLike.mjs +1 -0
- package/dist/esm/util/clean.d.mts +7 -0
- package/dist/esm/util/clean.mjs +13 -0
- package/dist/esm/util/regexHelper.d.mts +7 -0
- package/dist/esm/util/regexHelper.mjs +8 -0
- package/dist/esm/util/repMap.d.mts +27 -0
- package/dist/esm/util/repMap.mjs +152 -0
- package/dist/esm/util/simpleCache.d.mts +46 -0
- package/dist/esm/util/simpleCache.mjs +135 -0
- package/dist/esm/util/text.d.mts +10 -0
- package/dist/esm/util/text.mjs +46 -0
- package/dist/esm/util/textMappers.d.mts +3 -0
- package/dist/esm/util/textMappers.mjs +15 -0
- package/dist/esm/util/types.d.mts +7 -0
- package/dist/esm/util/types.mjs +1 -0
- package/dist/esm/util/util.d.mts +2 -0
- package/dist/esm/util/util.mjs +3 -0
- package/package.json +27 -18
- package/dist/SpellingDictionary/Typos/index.d.ts +0 -4
- package/dist/SpellingDictionary/createInlineSpellingDictionary.js +0 -25
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionary.d.ts +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionary.js +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Terms/index.js +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Terms/terms.d.ts +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Terms/terms.js +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/typos.js +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/util.js +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/defaults.d.ts +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/defaults.js +0 -0
- /package/dist/{util → cjs/util}/AutoCache.d.ts +0 -0
- /package/dist/{util → cjs/util}/AutoCache.js +0 -0
- /package/dist/{util → cjs/util}/AutoResolve.d.ts +0 -0
- /package/dist/{util → cjs/util}/AutoResolve.js +0 -0
- /package/dist/{util → cjs/util}/IterableLike.d.ts +0 -0
- /package/dist/{util → cjs/util}/IterableLike.js +0 -0
- /package/dist/{util → cjs/util}/clean.js +0 -0
- /package/dist/{util → cjs/util}/regexHelper.d.ts +0 -0
- /package/dist/{util → cjs/util}/regexHelper.js +0 -0
- /package/dist/{util → cjs/util}/repMap.d.ts +0 -0
- /package/dist/{util → cjs/util}/simpleCache.d.ts +0 -0
- /package/dist/{util → cjs/util}/simpleCache.js +0 -0
- /package/dist/{util → cjs/util}/text.d.ts +0 -0
- /package/dist/{util → cjs/util}/text.js +0 -0
- /package/dist/{util → cjs/util}/textMappers.d.ts +0 -0
- /package/dist/{util → cjs/util}/types.d.ts +0 -0
- /package/dist/{util → cjs/util}/types.js +0 -0
- /package/dist/{util → cjs/util}/util.d.ts +0 -0
- /package/dist/{util → cjs/util}/util.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { CacheStats } from '../util/AutoCache';
|
|
2
|
-
import type { SearchOptions, SpellingDictionary } from './SpellingDictionary';
|
|
3
|
-
import type { SpellingDictionaryCollection } from './SpellingDictionaryCollection';
|
|
1
|
+
import type { CacheStats } from '../util/AutoCache.js';
|
|
2
|
+
import type { SearchOptions, SpellingDictionary } from './SpellingDictionary.js';
|
|
3
|
+
import type { SpellingDictionaryCollection } from './SpellingDictionaryCollection.js';
|
|
4
4
|
interface CallStats {
|
|
5
5
|
name: string;
|
|
6
6
|
id: number;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createCachingDictionary = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const AutoCache_js_1 = require("../util/AutoCache.js");
|
|
5
|
+
const SpellingDictionaryMethods_js_1 = require("./SpellingDictionaryMethods.js");
|
|
6
6
|
let dictionaryCounter = 0;
|
|
7
7
|
class CachedDict {
|
|
8
8
|
constructor(dict, options) {
|
|
9
9
|
this.dict = dict;
|
|
10
10
|
this.options = options;
|
|
11
11
|
this.id = ++dictionaryCounter;
|
|
12
|
-
this.has = (0,
|
|
13
|
-
this.isNoSuggestWord = (0,
|
|
14
|
-
this.isForbidden = (0,
|
|
12
|
+
this.has = (0, AutoCache_js_1.autoCache)((word) => this.dict.has(word, this.options));
|
|
13
|
+
this.isNoSuggestWord = (0, AutoCache_js_1.autoCache)((word) => this.dict.isNoSuggestWord(word, this.options));
|
|
14
|
+
this.isForbidden = (0, AutoCache_js_1.autoCache)((word) => this.dict.isForbidden(word));
|
|
15
15
|
this.name = dict.name;
|
|
16
16
|
// console.log(`CachedDict for ${this.name}`);
|
|
17
17
|
}
|
|
@@ -19,9 +19,9 @@ class CachedDict {
|
|
|
19
19
|
return {
|
|
20
20
|
name: this.name,
|
|
21
21
|
id: this.id,
|
|
22
|
-
has: (0,
|
|
23
|
-
isNoSuggestWord: (0,
|
|
24
|
-
isForbidden: (0,
|
|
22
|
+
has: (0, AutoCache_js_1.extractStats)(this.has),
|
|
23
|
+
isNoSuggestWord: (0, AutoCache_js_1.extractStats)(this.isNoSuggestWord),
|
|
24
|
+
isForbidden: (0, AutoCache_js_1.extractStats)(this.isForbidden),
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -33,7 +33,7 @@ const knownDicts = new Map();
|
|
|
33
33
|
* @returns CachingDictionary
|
|
34
34
|
*/
|
|
35
35
|
function createCachingDictionary(dict, options) {
|
|
36
|
-
options = (0,
|
|
36
|
+
options = (0, SpellingDictionaryMethods_js_1.canonicalSearchOptions)(options);
|
|
37
37
|
let knownOptions = knownDicts.get(options);
|
|
38
38
|
if (!knownOptions) {
|
|
39
39
|
knownOptions = new WeakMap();
|
|
@@ -26,15 +26,15 @@ 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
|
|
30
|
-
const Defaults = __importStar(require("./defaults"));
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
class FlagWordsDictionaryTrie extends
|
|
29
|
+
const AutoResolve_js_1 = require("../util/AutoResolve.js");
|
|
30
|
+
const Defaults = __importStar(require("./defaults.js"));
|
|
31
|
+
const SpellingDictionary_js_1 = require("./SpellingDictionary.js");
|
|
32
|
+
const SpellingDictionaryFromTrie_js_1 = require("./SpellingDictionaryFromTrie.js");
|
|
33
|
+
const SpellingDictionaryMethods_js_1 = require("./SpellingDictionaryMethods.js");
|
|
34
|
+
const TyposDictionary_js_1 = require("./TyposDictionary.js");
|
|
35
|
+
class FlagWordsDictionaryTrie extends SpellingDictionaryFromTrie_js_1.SpellingDictionaryFromTrie {
|
|
36
36
|
constructor(trie, name, source) {
|
|
37
|
-
super(trie, name,
|
|
37
|
+
super(trie, name, SpellingDictionary_js_1.defaultOptions, source);
|
|
38
38
|
this.name = name;
|
|
39
39
|
this.source = source;
|
|
40
40
|
this.containsNoSuggestWords = false;
|
|
@@ -104,7 +104,7 @@ class FlagWordsDictionary {
|
|
|
104
104
|
}
|
|
105
105
|
suggest(...args) {
|
|
106
106
|
const [word] = args;
|
|
107
|
-
const suggestOptions = (0,
|
|
107
|
+
const suggestOptions = (0, SpellingDictionaryMethods_js_1.suggestArgsToSuggestOptions)(args);
|
|
108
108
|
return this.dictTypos.suggest(word, suggestOptions);
|
|
109
109
|
}
|
|
110
110
|
genSuggestions() {
|
|
@@ -120,7 +120,7 @@ class FlagWordsDictionary {
|
|
|
120
120
|
return [];
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
const createCache = (0,
|
|
123
|
+
const createCache = (0, AutoResolve_js_1.createAutoResolveWeakCache)();
|
|
124
124
|
/**
|
|
125
125
|
* Create a dictionary where all words are to be forbidden.
|
|
126
126
|
* @param wordList - list of words
|
|
@@ -134,7 +134,7 @@ function createFlagWordsDictionary(wordList, name, source) {
|
|
|
134
134
|
const testSpecialCharacters = /[~*+]/;
|
|
135
135
|
const { t: specialWords, f: typoWords } = bisect((0, cspell_trie_lib_1.parseDictionaryLines)(wordList, { stripCaseAndAccents: false }), (line) => testSpecialCharacters.test(line));
|
|
136
136
|
const trieDict = specialWords.size ? buildTrieDict(specialWords, name, source) : undefined;
|
|
137
|
-
const typosDict = (0,
|
|
137
|
+
const typosDict = (0, TyposDictionary_js_1.createTyposDictionary)(typoWords, name, source);
|
|
138
138
|
if (!trieDict)
|
|
139
139
|
return typosDict;
|
|
140
140
|
return new FlagWordsDictionary(name, source, typosDict, trieDict);
|
|
@@ -26,9 +26,9 @@ 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
|
|
30
|
-
const
|
|
31
|
-
const Defaults = __importStar(require("./defaults"));
|
|
29
|
+
const AutoResolve_js_1 = require("../util/AutoResolve.js");
|
|
30
|
+
const createSpellingDictionary_js_1 = require("./createSpellingDictionary.js");
|
|
31
|
+
const Defaults = __importStar(require("./defaults.js"));
|
|
32
32
|
const NormalizeForm = 'NFC';
|
|
33
33
|
class IgnoreWordsDictionary {
|
|
34
34
|
constructor(name, source, words) {
|
|
@@ -95,7 +95,7 @@ class IgnoreWordsDictionary {
|
|
|
95
95
|
return [];
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
const createCache = (0,
|
|
98
|
+
const createCache = (0, AutoResolve_js_1.createAutoResolveWeakCache)();
|
|
99
99
|
/**
|
|
100
100
|
* Create a dictionary where all words are to be ignored.
|
|
101
101
|
* Ignored words override forbidden words.
|
|
@@ -110,7 +110,7 @@ function createIgnoreWordsDictionary(wordList, name, source) {
|
|
|
110
110
|
const words = [...(0, cspell_trie_lib_1.parseDictionaryLines)(wordList, { stripCaseAndAccents: true })].map((w) => w.normalize(NormalizeForm));
|
|
111
111
|
const hasSpecial = words.findIndex((word) => testSpecialCharacters.test(word)) >= 0;
|
|
112
112
|
if (hasSpecial) {
|
|
113
|
-
return (0,
|
|
113
|
+
return (0, createSpellingDictionary_js_1.createSpellingDictionary)(words, name, source, {
|
|
114
114
|
caseSensitive: true,
|
|
115
115
|
noSuggest: true,
|
|
116
116
|
weightMap: undefined,
|
package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryCollection.d.ts
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SearchOptions, SpellingDictionary } from './SpellingDictionary';
|
|
1
|
+
import type { SearchOptions, SpellingDictionary } from './SpellingDictionary.js';
|
|
2
2
|
export interface SpellingDictionaryCollection extends SpellingDictionary {
|
|
3
3
|
readonly type: 'SpellingDictionaryCollection';
|
|
4
4
|
readonly dictionaries: SpellingDictionary[];
|
|
@@ -26,10 +26,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.__testing__ = exports.isSpellingDictionaryCollection = exports.createCollection = void 0;
|
|
27
27
|
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
28
28
|
const gensequence_1 = require("gensequence");
|
|
29
|
-
const
|
|
30
|
-
const Defaults = __importStar(require("./defaults"));
|
|
31
|
-
const
|
|
32
|
-
const
|
|
29
|
+
const util_js_1 = require("../util/util.js");
|
|
30
|
+
const Defaults = __importStar(require("./defaults.js"));
|
|
31
|
+
const SpellingDictionary_js_1 = require("./SpellingDictionary.js");
|
|
32
|
+
const SpellingDictionaryMethods_js_1 = require("./SpellingDictionaryMethods.js");
|
|
33
33
|
function identityString(w) {
|
|
34
34
|
return w;
|
|
35
35
|
}
|
|
@@ -51,11 +51,11 @@ class SpellingDictionaryCollectionImpl {
|
|
|
51
51
|
this.containsNoSuggestWords = this.dictionaries.reduce((a, b) => a || b.containsNoSuggestWords, false);
|
|
52
52
|
}
|
|
53
53
|
has(word, hasOptions) {
|
|
54
|
-
const options = (0,
|
|
54
|
+
const options = (0, SpellingDictionaryMethods_js_1.hasOptionToSearchOption)(hasOptions);
|
|
55
55
|
return !!isWordInAnyDictionary(this.dictionaries, word, options) && !this.isForbidden(word);
|
|
56
56
|
}
|
|
57
57
|
find(word, hasOptions) {
|
|
58
|
-
const options = (0,
|
|
58
|
+
const options = (0, SpellingDictionaryMethods_js_1.hasOptionToSearchOption)(hasOptions);
|
|
59
59
|
return findInAnyDictionary(this.dictionaries, word, options);
|
|
60
60
|
}
|
|
61
61
|
isNoSuggestWord(word, options) {
|
|
@@ -67,11 +67,11 @@ class SpellingDictionaryCollectionImpl {
|
|
|
67
67
|
}
|
|
68
68
|
suggest(...args) {
|
|
69
69
|
const [word] = args;
|
|
70
|
-
const suggestOptions = (0,
|
|
70
|
+
const suggestOptions = (0, SpellingDictionaryMethods_js_1.suggestArgsToSuggestOptions)(args);
|
|
71
71
|
return this._suggest(word, suggestOptions);
|
|
72
72
|
}
|
|
73
73
|
_suggest(word, suggestOptions) {
|
|
74
|
-
const { numSuggestions =
|
|
74
|
+
const { numSuggestions = SpellingDictionaryMethods_js_1.defaultNumSuggestions, numChanges, ignoreCase, includeTies, timeout } = suggestOptions;
|
|
75
75
|
const prefixNoCase = cspell_trie_lib_1.CASE_INSENSITIVE_PREFIX;
|
|
76
76
|
const filter = (word, _cost) => {
|
|
77
77
|
return ((ignoreCase || word[0] !== prefixNoCase) &&
|
|
@@ -86,7 +86,7 @@ class SpellingDictionaryCollectionImpl {
|
|
|
86
86
|
ignoreCase,
|
|
87
87
|
timeout,
|
|
88
88
|
};
|
|
89
|
-
const collector = (0,
|
|
89
|
+
const collector = (0, SpellingDictionaryMethods_js_1.suggestionCollector)(word, collectorOptions);
|
|
90
90
|
this.genSuggestions(collector, suggestOptions);
|
|
91
91
|
return collector.suggestions.map((r) => ({ ...r, word: r.word }));
|
|
92
92
|
}
|
|
@@ -95,8 +95,8 @@ class SpellingDictionaryCollectionImpl {
|
|
|
95
95
|
}
|
|
96
96
|
genSuggestions(collector, suggestOptions) {
|
|
97
97
|
const _suggestOptions = { ...suggestOptions };
|
|
98
|
-
const { compoundMethod =
|
|
99
|
-
_suggestOptions.compoundMethod = this.options.useCompounds ?
|
|
98
|
+
const { compoundMethod = SpellingDictionary_js_1.CompoundWordsMethod.SEPARATE_WORDS } = suggestOptions;
|
|
99
|
+
_suggestOptions.compoundMethod = this.options.useCompounds ? SpellingDictionary_js_1.CompoundWordsMethod.JOIN_WORDS : compoundMethod;
|
|
100
100
|
this.dictionaries.forEach((dict) => dict.genSuggestions(collector, _suggestOptions));
|
|
101
101
|
}
|
|
102
102
|
getErrors() {
|
|
@@ -114,7 +114,7 @@ function isWordInAnyDictionary(dicts, word, options) {
|
|
|
114
114
|
return (0, gensequence_1.genSequence)(dicts).first((dict) => dict.has(word, options));
|
|
115
115
|
}
|
|
116
116
|
function findInAnyDictionary(dicts, word, options) {
|
|
117
|
-
const found = dicts.map((dict) => dict.find(word, options)).filter(
|
|
117
|
+
const found = dicts.map((dict) => dict.find(word, options)).filter(util_js_1.isDefined);
|
|
118
118
|
if (!found.length)
|
|
119
119
|
return undefined;
|
|
120
120
|
return found.reduce((a, b) => ({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SuggestionCollector, SuggestionResult } from 'cspell-trie-lib';
|
|
2
2
|
import { CompoundWordsMethod, Trie } from 'cspell-trie-lib';
|
|
3
|
-
import type { FindResult, HasOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestOptions } from './SpellingDictionary';
|
|
3
|
+
import type { FindResult, HasOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestOptions } from './SpellingDictionary.js';
|
|
4
4
|
export declare class SpellingDictionaryFromTrie implements SpellingDictionary {
|
|
5
5
|
readonly trie: Trie;
|
|
6
6
|
readonly name: string;
|
|
@@ -26,11 +26,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.__testing__ = exports.createSpellingDictionaryFromTrieFile = exports.SpellingDictionaryFromTrie = 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
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const Defaults = __importStar(require("./defaults"));
|
|
33
|
-
const
|
|
29
|
+
const AutoCache_js_1 = require("../util/AutoCache.js");
|
|
30
|
+
const clean_js_1 = require("../util/clean.js");
|
|
31
|
+
const repMap_js_1 = require("../util/repMap.js");
|
|
32
|
+
const Defaults = __importStar(require("./defaults.js"));
|
|
33
|
+
const SpellingDictionaryMethods_js_1 = require("./SpellingDictionaryMethods.js");
|
|
34
34
|
const findWordOptionsCaseSensitive = Object.freeze({ caseSensitive: true });
|
|
35
35
|
const findWordOptionsNotCaseSensitive = Object.freeze({ caseSensitive: false });
|
|
36
36
|
class SpellingDictionaryFromTrie {
|
|
@@ -44,15 +44,15 @@ class SpellingDictionaryFromTrie {
|
|
|
44
44
|
this.unknownWords = new Set();
|
|
45
45
|
this.type = 'SpellingDictionaryFromTrie';
|
|
46
46
|
this._find = findCache((word, useCompounds, ignoreCase) => this.findAnyForm(word, useCompounds, ignoreCase));
|
|
47
|
-
this._isForbidden = (0,
|
|
47
|
+
this._isForbidden = (0, AutoCache_js_1.autoCache)((word) => {
|
|
48
48
|
return this.trie.isForbiddenWord(word);
|
|
49
49
|
});
|
|
50
|
-
this.mapWord = (0,
|
|
51
|
-
this.remapWord = (0,
|
|
50
|
+
this.mapWord = (0, repMap_js_1.createMapper)(options.repMap, options.dictionaryInformation?.ignore);
|
|
51
|
+
this.remapWord = (0, repMap_js_1.createRepMapper)(options.repMap, options.dictionaryInformation?.ignore);
|
|
52
52
|
this.isDictionaryCaseSensitive = options.caseSensitive ?? !trie.isLegacy;
|
|
53
53
|
this.containsNoSuggestWords = options.noSuggest || false;
|
|
54
54
|
this._size = size || 0;
|
|
55
|
-
this.weightMap = options.weightMap || (0,
|
|
55
|
+
this.weightMap = options.weightMap || (0, SpellingDictionaryMethods_js_1.createWeightMapFromDictionaryInformation)(options.dictionaryInformation);
|
|
56
56
|
}
|
|
57
57
|
get size() {
|
|
58
58
|
if (!this._size) {
|
|
@@ -86,7 +86,7 @@ class SpellingDictionaryFromTrie {
|
|
|
86
86
|
return { found, forbidden, noSuggest };
|
|
87
87
|
}
|
|
88
88
|
resolveOptions(hasOptions) {
|
|
89
|
-
const { useCompounds = this.options.useCompounds, ignoreCase = Defaults.ignoreCase } = (0,
|
|
89
|
+
const { useCompounds = this.options.useCompounds, ignoreCase = Defaults.ignoreCase } = (0, SpellingDictionaryMethods_js_1.hasOptionToSearchOption)(hasOptions);
|
|
90
90
|
return { useCompounds, ignoreCase };
|
|
91
91
|
}
|
|
92
92
|
findAnyForm(word, useCompounds, ignoreCase) {
|
|
@@ -104,7 +104,7 @@ class SpellingDictionaryFromTrie {
|
|
|
104
104
|
if (findResult.found !== false) {
|
|
105
105
|
return findResult;
|
|
106
106
|
}
|
|
107
|
-
const forms = (0,
|
|
107
|
+
const forms = (0, SpellingDictionaryMethods_js_1.wordSearchForms)(mWord, this.isDictionaryCaseSensitive, ignoreCase);
|
|
108
108
|
for (const w of forms) {
|
|
109
109
|
const findResult = this.trie.findWord(w, opts);
|
|
110
110
|
if (findResult.found !== false) {
|
|
@@ -130,15 +130,15 @@ class SpellingDictionaryFromTrie {
|
|
|
130
130
|
}
|
|
131
131
|
suggest(...args) {
|
|
132
132
|
const [word] = args;
|
|
133
|
-
const suggestOptions = (0,
|
|
133
|
+
const suggestOptions = (0, SpellingDictionaryMethods_js_1.suggestArgsToSuggestOptions)(args);
|
|
134
134
|
return this._suggest(word, suggestOptions);
|
|
135
135
|
}
|
|
136
136
|
_suggest(word, suggestOptions) {
|
|
137
|
-
const { numSuggestions =
|
|
137
|
+
const { numSuggestions = SpellingDictionaryMethods_js_1.defaultNumSuggestions, numChanges, includeTies, ignoreCase, timeout } = suggestOptions;
|
|
138
138
|
function filter(_word) {
|
|
139
139
|
return true;
|
|
140
140
|
}
|
|
141
|
-
const collector = (0, cspell_trie_lib_1.suggestionCollector)(word, (0,
|
|
141
|
+
const collector = (0, cspell_trie_lib_1.suggestionCollector)(word, (0, clean_js_1.clean)({
|
|
142
142
|
numSuggestions,
|
|
143
143
|
filter,
|
|
144
144
|
changeLimit: numChanges,
|
|
@@ -155,7 +155,7 @@ class SpellingDictionaryFromTrie {
|
|
|
155
155
|
return;
|
|
156
156
|
const _compoundMethod = suggestOptions.compoundMethod ??
|
|
157
157
|
(this.options.useCompounds ? cspell_trie_lib_1.CompoundWordsMethod.JOIN_WORDS : cspell_trie_lib_1.CompoundWordsMethod.NONE);
|
|
158
|
-
(0,
|
|
158
|
+
(0, SpellingDictionaryMethods_js_1.wordSuggestFormsArray)(collector.word).forEach((w) => this.trie.genSuggestions((0, SpellingDictionaryMethods_js_1.impersonateCollector)(collector, w), _compoundMethod));
|
|
159
159
|
}
|
|
160
160
|
getErrors() {
|
|
161
161
|
return [];
|
|
@@ -179,7 +179,7 @@ function createSpellingDictionaryFromTrieFile(data, name, source, options) {
|
|
|
179
179
|
}
|
|
180
180
|
exports.createSpellingDictionaryFromTrieFile = createSpellingDictionaryFromTrieFile;
|
|
181
181
|
function findCache(fn, size = 2000) {
|
|
182
|
-
const cache = (0,
|
|
182
|
+
const cache = (0, AutoCache_js_1.createCache01)(size);
|
|
183
183
|
function find(word, useCompounds, ignoreCase) {
|
|
184
184
|
const r = cache.get(word);
|
|
185
185
|
if (r !== undefined) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DictionaryInformation } from '@cspell/cspell-types';
|
|
2
2
|
import type { SuggestionResult, WeightMap } from 'cspell-trie-lib';
|
|
3
|
-
import type { HasOptions, SearchOptions, SuggestArgs, SuggestOptions } from './SpellingDictionary';
|
|
3
|
+
import type { HasOptions, SearchOptions, SuggestArgs, SuggestOptions } from './SpellingDictionary.js';
|
|
4
4
|
export { impersonateCollector, suggestionCollector } from 'cspell-trie-lib';
|
|
5
5
|
export type FilterSuggestionsPredicate = (word: SuggestionResult) => boolean;
|
|
6
6
|
export declare const defaultNumSuggestions = 10;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.__testMethods__ = exports.createWeightMapFromDictionaryInformation = exports.suggestArgsToSuggestOptions = exports.canonicalSearchOptions = exports.hasOptionToSearchOption = exports.wordSuggestForms = exports.wordSuggestFormsArray = exports.wordSearchForms = exports.defaultNumSuggestions = exports.suggestionCollector = exports.impersonateCollector = void 0;
|
|
4
4
|
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
|
-
const
|
|
5
|
+
const text_js_1 = require("../util/text.js");
|
|
6
6
|
var cspell_trie_lib_2 = require("cspell-trie-lib");
|
|
7
7
|
Object.defineProperty(exports, "impersonateCollector", { enumerable: true, get: function () { return cspell_trie_lib_2.impersonateCollector; } });
|
|
8
8
|
Object.defineProperty(exports, "suggestionCollector", { enumerable: true, get: function () { return cspell_trie_lib_2.suggestionCollector; } });
|
|
@@ -21,7 +21,7 @@ function wordSearchForms(word, isDictionaryCaseSensitive, ignoreCase) {
|
|
|
21
21
|
else {
|
|
22
22
|
forms.add(wordLc);
|
|
23
23
|
// Legacy remove any unbound accents
|
|
24
|
-
forms.add((0,
|
|
24
|
+
forms.add((0, text_js_1.removeUnboundAccents)(wordLc));
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
@@ -29,14 +29,14 @@ function wordSearchForms(word, isDictionaryCaseSensitive, ignoreCase) {
|
|
|
29
29
|
forms.add(word);
|
|
30
30
|
forms.add(wordLc);
|
|
31
31
|
// HOUSE -> House, house
|
|
32
|
-
if ((0,
|
|
33
|
-
forms.add((0,
|
|
32
|
+
if ((0, text_js_1.isUpperCase)(word)) {
|
|
33
|
+
forms.add((0, text_js_1.ucFirst)(wordLc));
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
37
|
forms.add(wordLc);
|
|
38
38
|
// Legacy remove any unbound accents
|
|
39
|
-
forms.add((0,
|
|
39
|
+
forms.add((0, text_js_1.removeUnboundAccents)(wordLc));
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
return forms;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IgnoreCaseOption, SpellingDictionary } from './SpellingDictionary';
|
|
2
|
-
import { type TypoEntry, type TyposDef } from './Typos';
|
|
1
|
+
import type { IgnoreCaseOption, SpellingDictionary } from './SpellingDictionary.js';
|
|
2
|
+
import { type TypoEntry, type TyposDef } from './Typos/index.js';
|
|
3
3
|
export interface SuggestDictionary extends SpellingDictionary {
|
|
4
4
|
/**
|
|
5
5
|
* Determine if the word can appear in a list of suggestions.
|
|
@@ -25,11 +25,11 @@ 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
|
|
29
|
-
const
|
|
30
|
-
const defaults = __importStar(require("./defaults"));
|
|
31
|
-
const
|
|
32
|
-
const
|
|
28
|
+
const AutoResolve_js_1 = require("../util/AutoResolve.js");
|
|
29
|
+
const textMappers_js_1 = require("../util/textMappers.js");
|
|
30
|
+
const defaults = __importStar(require("./defaults.js"));
|
|
31
|
+
const index_js_1 = require("./Typos/index.js");
|
|
32
|
+
const util_js_1 = require("./Typos/util.js");
|
|
33
33
|
class SuggestDictionaryImpl {
|
|
34
34
|
constructor(name, source, typosDef) {
|
|
35
35
|
this.name = name;
|
|
@@ -40,8 +40,8 @@ class SuggestDictionaryImpl {
|
|
|
40
40
|
this.type = 'suggest';
|
|
41
41
|
this.isDictionaryCaseSensitive = true;
|
|
42
42
|
this.size = Object.keys(typosDef).length;
|
|
43
|
-
this.suggestions = (0,
|
|
44
|
-
this.suggestionsLower = new Set((0, sync_1.pipe)(this.suggestions,
|
|
43
|
+
this.suggestions = (0, util_js_1.extractAllSuggestions)(typosDef);
|
|
44
|
+
this.suggestionsLower = new Set((0, sync_1.pipe)(this.suggestions, textMappers_js_1.mapperRemoveCaseAndAccents));
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* A Forbidden word list does not "have" valid words.
|
|
@@ -107,7 +107,7 @@ class SuggestDictionaryImpl {
|
|
|
107
107
|
return [];
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
const createCache = (0,
|
|
110
|
+
const createCache = (0, AutoResolve_js_1.createAutoResolveWeakCache)();
|
|
111
111
|
/**
|
|
112
112
|
* Create a dictionary where all words are to be forbidden.
|
|
113
113
|
* @param entries - list of Typos Entries
|
|
@@ -117,7 +117,7 @@ const createCache = (0, AutoResolve_1.createAutoResolveWeakCache)();
|
|
|
117
117
|
*/
|
|
118
118
|
function createSuggestDictionary(entries, name, source) {
|
|
119
119
|
return createCache.get(entries, () => {
|
|
120
|
-
const def = (0,
|
|
120
|
+
const def = (0, index_js_1.processEntriesToTyposDef)(entries);
|
|
121
121
|
return new SuggestDictionaryImpl(name, source, def);
|
|
122
122
|
});
|
|
123
123
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { TermsDef, TermsDefKey, TermsDefValue, TermValueIgnoreWord, TermValueOk, TermValueTypo, TermValueTypoNoSuggestions, TermValueTypoWithSuggestions, } from './terms';
|
|
1
|
+
export { TermsDef, TermsDefKey, TermsDefValue, TermValueIgnoreWord, TermValueOk, TermValueTypo, TermValueTypoNoSuggestions, TermValueTypoWithSuggestions, } from './terms.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractAllSuggestions = exports.createTyposDef = exports.processEntriesToTyposDef = exports.parseTyposLine = exports.parseTyposFile = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "parseTyposFile", { enumerable: true, get: function () { return
|
|
6
|
-
Object.defineProperty(exports, "parseTyposLine", { enumerable: true, get: function () { return
|
|
7
|
-
Object.defineProperty(exports, "processEntriesToTyposDef", { enumerable: true, get: function () { return
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "createTyposDef", { enumerable: true, get: function () { return
|
|
10
|
-
Object.defineProperty(exports, "extractAllSuggestions", { enumerable: true, get: function () { return
|
|
4
|
+
var typosParser_js_1 = require("./typosParser.js");
|
|
5
|
+
Object.defineProperty(exports, "parseTyposFile", { enumerable: true, get: function () { return typosParser_js_1.parseTyposFile; } });
|
|
6
|
+
Object.defineProperty(exports, "parseTyposLine", { enumerable: true, get: function () { return typosParser_js_1.parseTyposLine; } });
|
|
7
|
+
Object.defineProperty(exports, "processEntriesToTyposDef", { enumerable: true, get: function () { return typosParser_js_1.processEntriesToTyposDef; } });
|
|
8
|
+
var util_js_1 = require("./util.js");
|
|
9
|
+
Object.defineProperty(exports, "createTyposDef", { enumerable: true, get: function () { return util_js_1.createTyposDef; } });
|
|
10
|
+
Object.defineProperty(exports, "extractAllSuggestions", { enumerable: true, get: function () { return util_js_1.extractAllSuggestions; } });
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TermsDefKey, TermValueTypo, TermValueTypoNoSuggestions, TermValueTypoWithSuggestions } from '../Terms';
|
|
1
|
+
import type { TermsDefKey, TermValueTypo, TermValueTypoNoSuggestions, TermValueTypoWithSuggestions } from '../Terms/index.js';
|
|
2
2
|
export type TypoValueNoSuggestions = TermValueTypoNoSuggestions;
|
|
3
3
|
export type TypoValueWithSuggestions = TermValueTypoWithSuggestions;
|
|
4
4
|
export type TyposDefValue = TermValueTypo;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TypoEntry, TyposDef } from './typos';
|
|
1
|
+
import type { TypoEntry, TyposDef } from './typos.js';
|
|
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,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.parseTyposFile = exports.parseTyposLine = exports.processEntriesToTyposDef = exports.sanitizeIntoTypoDef = exports.createTyposDefFromEntries = void 0;
|
|
7
7
|
const assert_1 = __importDefault(require("assert"));
|
|
8
|
-
const
|
|
8
|
+
const util_js_1 = require("./util.js");
|
|
9
9
|
function assertString(v) {
|
|
10
10
|
(0, assert_1.default)(typeof v === 'string', 'A string was expected.');
|
|
11
11
|
return true;
|
|
@@ -17,7 +17,7 @@ const inlineComment = /#.*/gm;
|
|
|
17
17
|
function createTyposDefFromEntries(entries) {
|
|
18
18
|
const def = Object.create(null);
|
|
19
19
|
for (const entry of entries) {
|
|
20
|
-
(0,
|
|
20
|
+
(0, util_js_1.appendToDef)(def, entry);
|
|
21
21
|
}
|
|
22
22
|
return def;
|
|
23
23
|
}
|
|
@@ -41,7 +41,7 @@ function splitSuggestionsValue(value) {
|
|
|
41
41
|
function sanitizeIntoTypoDef(dirtyDef) {
|
|
42
42
|
if (!dirtyDef || typeof dirtyDef !== 'object')
|
|
43
43
|
return undefined;
|
|
44
|
-
const def = (0,
|
|
44
|
+
const def = (0, util_js_1.createTyposDef)();
|
|
45
45
|
for (const [rawKey, value] of Object.entries(dirtyDef)) {
|
|
46
46
|
const key = normalize(rawKey.trim());
|
|
47
47
|
if (!key)
|
|
@@ -91,9 +91,9 @@ function processEntriesToTyposDef(entries) {
|
|
|
91
91
|
}
|
|
92
92
|
exports.processEntriesToTyposDef = processEntriesToTyposDef;
|
|
93
93
|
function reduceToTyposDef(entries) {
|
|
94
|
-
const def = (0,
|
|
94
|
+
const def = (0, util_js_1.createTyposDef)();
|
|
95
95
|
for (const entry of entries) {
|
|
96
|
-
(0,
|
|
96
|
+
(0, util_js_1.appendToDef)(def, parseTyposLine(entry));
|
|
97
97
|
}
|
|
98
98
|
return def;
|
|
99
99
|
}
|
|
@@ -106,7 +106,7 @@ function parseTyposLine(line) {
|
|
|
106
106
|
if (!line)
|
|
107
107
|
return undefined;
|
|
108
108
|
if (typeof line === 'string') {
|
|
109
|
-
const def = (0,
|
|
109
|
+
const def = (0, util_js_1.createTyposDef)();
|
|
110
110
|
for (const subEntry of splitIntoLines(line)) {
|
|
111
111
|
const [left, right] = splitEntry(subEntry);
|
|
112
112
|
const typo = left.trim();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TypoEntry, TyposDef, TyposDefKey, TyposDefValue } from './typos';
|
|
1
|
+
import type { TypoEntry, TyposDef, TyposDefKey, TyposDefValue } from './typos.js';
|
|
2
2
|
export declare function mergeDefEntry(targetDef: TyposDef, key: string, value: TyposDefValue): TyposDef;
|
|
3
3
|
/**
|
|
4
4
|
* Merge in place the entries `fromDef` into `targetDef`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IgnoreCaseOption, SpellingDictionary } from './SpellingDictionary';
|
|
2
|
-
import { type TypoEntry, type TyposDef } from './Typos';
|
|
1
|
+
import type { IgnoreCaseOption, SpellingDictionary } from './SpellingDictionary.js';
|
|
2
|
+
import { type TypoEntry, type TyposDef } from './Typos/index.js';
|
|
3
3
|
export interface TyposDictionary extends SpellingDictionary {
|
|
4
4
|
isForbidden(word: string, ignoreCaseAndAccents?: IgnoreCaseOption): boolean;
|
|
5
5
|
/**
|
|
@@ -25,11 +25,11 @@ 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
|
|
29
|
-
const
|
|
30
|
-
const defaults = __importStar(require("./defaults"));
|
|
31
|
-
const
|
|
32
|
-
const
|
|
28
|
+
const AutoResolve_js_1 = require("../util/AutoResolve.js");
|
|
29
|
+
const textMappers_js_1 = require("../util/textMappers.js");
|
|
30
|
+
const defaults = __importStar(require("./defaults.js"));
|
|
31
|
+
const index_js_1 = require("./Typos/index.js");
|
|
32
|
+
const util_js_1 = require("./Typos/util.js");
|
|
33
33
|
class TyposDictionaryImpl {
|
|
34
34
|
constructor(name, source, typosDef, ignoreList) {
|
|
35
35
|
this.name = name;
|
|
@@ -39,10 +39,10 @@ class TyposDictionaryImpl {
|
|
|
39
39
|
this.type = 'typos';
|
|
40
40
|
this.isDictionaryCaseSensitive = true;
|
|
41
41
|
this.size = Object.keys(typosDef).length;
|
|
42
|
-
this.explicitIgnoreWords = (0,
|
|
43
|
-
this.suggestions = (0,
|
|
42
|
+
this.explicitIgnoreWords = (0, util_js_1.extractIgnoreValues)(typosDef, '!');
|
|
43
|
+
this.suggestions = (0, util_js_1.extractAllSuggestions)(typosDef);
|
|
44
44
|
this.ignoreWords = new Set((0, sync_1.pipe)(this.explicitIgnoreWords, (0, sync_1.opAppend)(ignoreList || [])));
|
|
45
|
-
this.suggestionsLower = new Set((0, sync_1.pipe)(this.suggestions,
|
|
45
|
+
this.suggestionsLower = new Set((0, sync_1.pipe)(this.suggestions, textMappers_js_1.mapperRemoveCaseAndAccents));
|
|
46
46
|
this.containsNoSuggestWords = this.ignoreWords.size > 0;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
@@ -139,7 +139,7 @@ class TyposDictionaryImpl {
|
|
|
139
139
|
return [];
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
const createCache = (0,
|
|
142
|
+
const createCache = (0, AutoResolve_js_1.createAutoResolveWeakCache)();
|
|
143
143
|
/**
|
|
144
144
|
* Create a dictionary where all words are to be forbidden.
|
|
145
145
|
* @param entries - list of Typos Entries
|
|
@@ -149,7 +149,7 @@ const createCache = (0, AutoResolve_1.createAutoResolveWeakCache)();
|
|
|
149
149
|
*/
|
|
150
150
|
function createTyposDictionary(entries, name, source) {
|
|
151
151
|
return createCache.get(entries, () => {
|
|
152
|
-
const def = (0,
|
|
152
|
+
const def = (0, index_js_1.processEntriesToTyposDef)(entries);
|
|
153
153
|
return new TyposDictionaryImpl(name, source, def);
|
|
154
154
|
});
|
|
155
155
|
}
|
package/dist/{SpellingDictionary → cjs/SpellingDictionary}/createInlineSpellingDictionary.d.ts
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { DictionaryDefinitionInline, SpellingDictionary } from './SpellingDictionary';
|
|
1
|
+
import type { DictionaryDefinitionInline, SpellingDictionary } from './SpellingDictionary.js';
|
|
2
2
|
export declare function createInlineSpellingDictionary(inlineDict: DictionaryDefinitionInline, source: string): SpellingDictionary;
|
|
3
3
|
//# sourceMappingURL=createInlineSpellingDictionary.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInlineSpellingDictionary = void 0;
|
|
4
|
+
const AutoResolve_js_1 = require("../util/AutoResolve.js");
|
|
5
|
+
const util_js_1 = require("../util/util.js");
|
|
6
|
+
const createSpellingDictionary_js_1 = require("./createSpellingDictionary.js");
|
|
7
|
+
const FlagWordsDictionary_js_1 = require("./FlagWordsDictionary.js");
|
|
8
|
+
const IgnoreWordsDictionary_js_1 = require("./IgnoreWordsDictionary.js");
|
|
9
|
+
const SpellingDictionaryCollection_js_1 = require("./SpellingDictionaryCollection.js");
|
|
10
|
+
const SuggestDictionary_js_1 = require("./SuggestDictionary.js");
|
|
11
|
+
const cache = (0, AutoResolve_js_1.createAutoResolveWeakCache)();
|
|
12
|
+
function createInlineSpellingDictionary(inlineDict, source) {
|
|
13
|
+
return cache.get(inlineDict, () => {
|
|
14
|
+
const { words, flagWords, ignoreWords, suggestWords, name } = inlineDict;
|
|
15
|
+
const dictSources = [
|
|
16
|
+
words && (0, createSpellingDictionary_js_1.createSpellingDictionary)(words, name + '-words', source, inlineDict),
|
|
17
|
+
flagWords && (0, FlagWordsDictionary_js_1.createFlagWordsDictionary)(flagWords, name + '-flag-words', source),
|
|
18
|
+
ignoreWords && (0, IgnoreWordsDictionary_js_1.createIgnoreWordsDictionary)(ignoreWords, name + '-ignore-words', source),
|
|
19
|
+
suggestWords && (0, SuggestDictionary_js_1.createSuggestDictionary)(suggestWords, name + '-suggest', source),
|
|
20
|
+
].filter(util_js_1.isDefined);
|
|
21
|
+
return (0, SpellingDictionaryCollection_js_1.createCollection)(dictSources, name, source);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.createInlineSpellingDictionary = createInlineSpellingDictionary;
|
|
25
|
+
//# sourceMappingURL=createInlineSpellingDictionary.js.map
|