cspell-dictionary 6.27.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}/SpellingDictionary.d.ts +7 -0
- 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 +3 -2
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryFromTrie.js +18 -17
- 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/cjs/util/repMap.d.ts +27 -0
- package/dist/cjs/util/repMap.js +158 -0
- 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 +29 -20
- package/dist/SpellingDictionary/Typos/index.d.ts +0 -4
- package/dist/SpellingDictionary/createInlineSpellingDictionary.js +0 -25
- package/dist/util/repMap.d.ts +0 -11
- package/dist/util/repMap.js +0 -65
- /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}/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
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { opMap, pipe } from '@cspell/cspell-pipe/sync';
|
|
2
|
+
import { buildTrieFast, parseDictionaryLines } from 'cspell-trie-lib';
|
|
3
|
+
import { createAutoResolveWeakCache } from '../util/AutoResolve.mjs';
|
|
4
|
+
import * as Defaults from './defaults.mjs';
|
|
5
|
+
import { defaultOptions } from './SpellingDictionary.mjs';
|
|
6
|
+
import { SpellingDictionaryFromTrie } from './SpellingDictionaryFromTrie.mjs';
|
|
7
|
+
import { suggestArgsToSuggestOptions } from './SpellingDictionaryMethods.mjs';
|
|
8
|
+
import { createTyposDictionary } from './TyposDictionary.mjs';
|
|
9
|
+
class FlagWordsDictionaryTrie extends SpellingDictionaryFromTrie {
|
|
10
|
+
constructor(trie, name, source) {
|
|
11
|
+
super(trie, name, defaultOptions, source);
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.source = source;
|
|
14
|
+
this.containsNoSuggestWords = false;
|
|
15
|
+
this.options = {};
|
|
16
|
+
this.isDictionaryCaseSensitive = true;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A Forbidden word list does not "have" valid words.
|
|
20
|
+
* Therefore it always returns false.
|
|
21
|
+
* @param _word - the word
|
|
22
|
+
* @param _options - options
|
|
23
|
+
* @returns always false
|
|
24
|
+
*/
|
|
25
|
+
has(_word, _options) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
find(word, hasOptions) {
|
|
29
|
+
const f = super.find(word, hasOptions);
|
|
30
|
+
if (!f || !f.forbidden)
|
|
31
|
+
return undefined;
|
|
32
|
+
return f;
|
|
33
|
+
}
|
|
34
|
+
suggest() {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
genSuggestions() {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class FlagWordsDictionary {
|
|
42
|
+
constructor(name, source, dictTypos, dictTrie) {
|
|
43
|
+
this.name = name;
|
|
44
|
+
this.source = source;
|
|
45
|
+
this.dictTypos = dictTypos;
|
|
46
|
+
this.dictTrie = dictTrie;
|
|
47
|
+
this.containsNoSuggestWords = false;
|
|
48
|
+
this.options = {};
|
|
49
|
+
this.type = 'flag-words';
|
|
50
|
+
this.isDictionaryCaseSensitive = true;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A Forbidden word list does not "have" valid words.
|
|
54
|
+
* Therefore it always returns false.
|
|
55
|
+
* @param word - the word
|
|
56
|
+
* @param options - options
|
|
57
|
+
* @returns always false
|
|
58
|
+
*/
|
|
59
|
+
has(word, options) {
|
|
60
|
+
return this.dictTypos.has(word, options) || this.dictTrie?.has(word, options) || false;
|
|
61
|
+
}
|
|
62
|
+
/** A more detailed search for a word, might take longer than `has` */
|
|
63
|
+
find(word, options) {
|
|
64
|
+
const findTypos = this.dictTypos.find(word, options);
|
|
65
|
+
if (findTypos)
|
|
66
|
+
return findTypos;
|
|
67
|
+
const ignoreCase = options?.ignoreCase ?? Defaults.ignoreCase;
|
|
68
|
+
if (this.dictTypos.isSuggestedWord(word, ignoreCase))
|
|
69
|
+
return undefined;
|
|
70
|
+
return this.dictTrie?.find(word, options);
|
|
71
|
+
}
|
|
72
|
+
isForbidden(word, ignoreCaseAndAccents = Defaults.isForbiddenIgnoreCaseAndAccents) {
|
|
73
|
+
const findResult = this.find(word, { ignoreCase: ignoreCaseAndAccents });
|
|
74
|
+
return findResult?.forbidden || false;
|
|
75
|
+
}
|
|
76
|
+
isNoSuggestWord(word, options) {
|
|
77
|
+
return this.dictTrie?.isNoSuggestWord(word, options) || this.dictTypos.isNoSuggestWord(word, options);
|
|
78
|
+
}
|
|
79
|
+
suggest(...args) {
|
|
80
|
+
const [word] = args;
|
|
81
|
+
const suggestOptions = suggestArgsToSuggestOptions(args);
|
|
82
|
+
return this.dictTypos.suggest(word, suggestOptions);
|
|
83
|
+
}
|
|
84
|
+
genSuggestions() {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
mapWord(word) {
|
|
88
|
+
return word;
|
|
89
|
+
}
|
|
90
|
+
get size() {
|
|
91
|
+
return this.dictTypos.size + (this.dictTrie?.size || 0);
|
|
92
|
+
}
|
|
93
|
+
getErrors() {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const createCache = createAutoResolveWeakCache();
|
|
98
|
+
/**
|
|
99
|
+
* Create a dictionary where all words are to be forbidden.
|
|
100
|
+
* @param wordList - list of words
|
|
101
|
+
* @param name
|
|
102
|
+
* @param source
|
|
103
|
+
* @param options
|
|
104
|
+
* @returns SpellingDictionary
|
|
105
|
+
*/
|
|
106
|
+
export function createFlagWordsDictionary(wordList, name, source) {
|
|
107
|
+
return createCache.get(wordList, () => {
|
|
108
|
+
const testSpecialCharacters = /[~*+]/;
|
|
109
|
+
const { t: specialWords, f: typoWords } = bisect(parseDictionaryLines(wordList, { stripCaseAndAccents: false }), (line) => testSpecialCharacters.test(line));
|
|
110
|
+
const trieDict = specialWords.size ? buildTrieDict(specialWords, name, source) : undefined;
|
|
111
|
+
const typosDict = createTyposDictionary(typoWords, name, source);
|
|
112
|
+
if (!trieDict)
|
|
113
|
+
return typosDict;
|
|
114
|
+
return new FlagWordsDictionary(name, source, typosDict, trieDict);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const regExpCleanIgnore = /^(!!)+/;
|
|
118
|
+
function buildTrieDict(words, name, source) {
|
|
119
|
+
const trie = buildTrieFast(pipe(words, opMap((w) => '!' + w), opMap((w) => w.replace(regExpCleanIgnore, ''))));
|
|
120
|
+
return new FlagWordsDictionaryTrie(trie, name, source);
|
|
121
|
+
}
|
|
122
|
+
function bisect(values, predicate) {
|
|
123
|
+
const t = new Set();
|
|
124
|
+
const f = new Set();
|
|
125
|
+
for (const v of values) {
|
|
126
|
+
if (predicate(v)) {
|
|
127
|
+
t.add(v);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
f.add(v);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return { t, f };
|
|
134
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SpellingDictionary } from './SpellingDictionary.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Create a dictionary where all words are to be ignored.
|
|
4
|
+
* Ignored words override forbidden words.
|
|
5
|
+
* @param wordList - list of words
|
|
6
|
+
* @param name - name of dictionary
|
|
7
|
+
* @param source - dictionary source
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function createIgnoreWordsDictionary(wordList: readonly string[], name: string, source: string): SpellingDictionary;
|
|
11
|
+
//# sourceMappingURL=IgnoreWordsDictionary.d.mts.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { opFilter, opMap, pipe } from '@cspell/cspell-pipe/sync';
|
|
2
|
+
import { parseDictionaryLines } from 'cspell-trie-lib';
|
|
3
|
+
import { createAutoResolveWeakCache } from '../util/AutoResolve.mjs';
|
|
4
|
+
import { createSpellingDictionary } from './createSpellingDictionary.mjs';
|
|
5
|
+
import * as Defaults from './defaults.mjs';
|
|
6
|
+
const NormalizeForm = 'NFC';
|
|
7
|
+
class IgnoreWordsDictionary {
|
|
8
|
+
constructor(name, source, words) {
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.source = source;
|
|
11
|
+
this.containsNoSuggestWords = true;
|
|
12
|
+
this.options = {};
|
|
13
|
+
this.type = 'ignore';
|
|
14
|
+
this.isDictionaryCaseSensitive = true;
|
|
15
|
+
this.dict = new Set(words);
|
|
16
|
+
this.dictNonStrict = new Set(pipe(this.dict, opFilter((w) => w.startsWith('~')), opMap((w) => w.slice(1))));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A Forbidden word list does not "have" valid words.
|
|
20
|
+
* Therefore it always returns false.
|
|
21
|
+
* @param _word - the word
|
|
22
|
+
* @param _options - options
|
|
23
|
+
* @returns always false
|
|
24
|
+
*/
|
|
25
|
+
has(word, options) {
|
|
26
|
+
const nWord = word.normalize(NormalizeForm);
|
|
27
|
+
if (this.dict.has(nWord))
|
|
28
|
+
return true;
|
|
29
|
+
const lcWord = nWord.toLowerCase();
|
|
30
|
+
if (this.dict.has(lcWord))
|
|
31
|
+
return true;
|
|
32
|
+
const ignoreCase = options?.ignoreCase ?? Defaults.ignoreCase;
|
|
33
|
+
return ignoreCase && (this.dictNonStrict.has(nWord) || this.dictNonStrict.has(lcWord));
|
|
34
|
+
}
|
|
35
|
+
/** A more detailed search for a word, might take longer than `has` */
|
|
36
|
+
find(word, options) {
|
|
37
|
+
const nWord = word.normalize(NormalizeForm);
|
|
38
|
+
if (this.dict.has(nWord))
|
|
39
|
+
return { found: nWord, forbidden: false, noSuggest: true };
|
|
40
|
+
const lcWord = nWord.toLowerCase();
|
|
41
|
+
if (this.dict.has(lcWord))
|
|
42
|
+
return { found: lcWord, forbidden: false, noSuggest: true };
|
|
43
|
+
const ignoreCase = options?.ignoreCase ?? Defaults.ignoreCase;
|
|
44
|
+
if (!ignoreCase)
|
|
45
|
+
return undefined;
|
|
46
|
+
if (this.dictNonStrict.has(nWord))
|
|
47
|
+
return { found: nWord, forbidden: false, noSuggest: true };
|
|
48
|
+
return (this.dictNonStrict.has(lcWord) && { found: lcWord, forbidden: false, noSuggest: true }) || undefined;
|
|
49
|
+
}
|
|
50
|
+
isForbidden(_word, _ignoreCase) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
isNoSuggestWord(word, options) {
|
|
54
|
+
return this.has(word, options);
|
|
55
|
+
}
|
|
56
|
+
suggest() {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
genSuggestions() {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
mapWord(word) {
|
|
63
|
+
return word;
|
|
64
|
+
}
|
|
65
|
+
get size() {
|
|
66
|
+
return this.dict.size;
|
|
67
|
+
}
|
|
68
|
+
getErrors() {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const createCache = createAutoResolveWeakCache();
|
|
73
|
+
/**
|
|
74
|
+
* Create a dictionary where all words are to be ignored.
|
|
75
|
+
* Ignored words override forbidden words.
|
|
76
|
+
* @param wordList - list of words
|
|
77
|
+
* @param name - name of dictionary
|
|
78
|
+
* @param source - dictionary source
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
export function createIgnoreWordsDictionary(wordList, name, source) {
|
|
82
|
+
return createCache.get(wordList, () => {
|
|
83
|
+
const testSpecialCharacters = /[*+]/;
|
|
84
|
+
const words = [...parseDictionaryLines(wordList, { stripCaseAndAccents: true })].map((w) => w.normalize(NormalizeForm));
|
|
85
|
+
const hasSpecial = words.findIndex((word) => testSpecialCharacters.test(word)) >= 0;
|
|
86
|
+
if (hasSpecial) {
|
|
87
|
+
return createSpellingDictionary(words, name, source, {
|
|
88
|
+
caseSensitive: true,
|
|
89
|
+
noSuggest: true,
|
|
90
|
+
weightMap: undefined,
|
|
91
|
+
supportNonStrictSearches: true,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return new IgnoreWordsDictionary(name, source, words);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { DictionaryInformation, ReplaceMap } from '@cspell/cspell-types';
|
|
2
|
+
import type { CompoundWordsMethod, SuggestionCollector, SuggestionResult, WeightMap } from 'cspell-trie-lib';
|
|
3
|
+
export type { DictionaryDefinitionInline } from '@cspell/cspell-types';
|
|
4
|
+
export { CompoundWordsMethod, type SuggestionCollector, type SuggestionResult } from 'cspell-trie-lib';
|
|
5
|
+
export interface SearchOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Legacy compounds have been deprecated.
|
|
8
|
+
*
|
|
9
|
+
* @deprecated
|
|
10
|
+
*/
|
|
11
|
+
useCompounds?: boolean | number | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Ignore Case and Accents
|
|
14
|
+
*/
|
|
15
|
+
ignoreCase?: boolean | undefined;
|
|
16
|
+
}
|
|
17
|
+
export interface SuggestOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Compounding Mode.
|
|
20
|
+
* `NONE` is the best option.
|
|
21
|
+
*/
|
|
22
|
+
compoundMethod?: CompoundWordsMethod | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* The limit on the number of suggestions to generate. If `allowTies` is true, it is possible
|
|
25
|
+
* for more suggestions to be generated.
|
|
26
|
+
*/
|
|
27
|
+
numSuggestions?: number | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Max number of changes / edits to the word to get to a suggestion matching suggestion.
|
|
30
|
+
*/
|
|
31
|
+
numChanges?: number | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Allow for case-ingestive checking.
|
|
34
|
+
*/
|
|
35
|
+
ignoreCase?: boolean | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* If multiple suggestions have the same edit / change "cost", then included them even if
|
|
38
|
+
* it causes more than `numSuggestions` to be returned.
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
includeTies?: boolean | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Maximum amount of time to allow for generating suggestions.
|
|
44
|
+
*/
|
|
45
|
+
timeout?: number | undefined;
|
|
46
|
+
}
|
|
47
|
+
export type FindOptions = SearchOptions;
|
|
48
|
+
export interface FindResult {
|
|
49
|
+
/** the text found, otherwise `false` */
|
|
50
|
+
found: string | false;
|
|
51
|
+
/** `true` if it is considered a forbidden word. */
|
|
52
|
+
forbidden: boolean;
|
|
53
|
+
/** `true` if it is a no-suggest word. */
|
|
54
|
+
noSuggest: boolean;
|
|
55
|
+
}
|
|
56
|
+
export type HasOptions = SearchOptions;
|
|
57
|
+
export type IgnoreCaseOption = boolean;
|
|
58
|
+
export interface SpellingDictionaryOptions {
|
|
59
|
+
repMap?: ReplaceMap;
|
|
60
|
+
/**
|
|
61
|
+
* The dictionary is case aware.
|
|
62
|
+
*/
|
|
63
|
+
caseSensitive?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* This is a NO Suggest dictionary used for words to be ignored.
|
|
66
|
+
*/
|
|
67
|
+
noSuggest?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Extra dictionary information used in improving suggestions
|
|
70
|
+
* based upon locale.
|
|
71
|
+
*/
|
|
72
|
+
dictionaryInformation?: DictionaryInformation;
|
|
73
|
+
/**
|
|
74
|
+
* Strip Case and Accents to allow for case insensitive searches and
|
|
75
|
+
* words without accents.
|
|
76
|
+
*
|
|
77
|
+
* Note: this setting only applies to word lists. It has no-impact on trie
|
|
78
|
+
* dictionaries.
|
|
79
|
+
*
|
|
80
|
+
* @default true
|
|
81
|
+
*/
|
|
82
|
+
supportNonStrictSearches?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Turns on legacy word compounds.
|
|
85
|
+
* @deprecated
|
|
86
|
+
*/
|
|
87
|
+
useCompounds?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Optional WeightMap used to improve suggestions.
|
|
90
|
+
*/
|
|
91
|
+
weightMap?: WeightMap | undefined;
|
|
92
|
+
}
|
|
93
|
+
export interface DictionaryInfo {
|
|
94
|
+
/** The name of the dictionary */
|
|
95
|
+
readonly name: string;
|
|
96
|
+
/** The source, filename or URI */
|
|
97
|
+
readonly source: string;
|
|
98
|
+
/** Options */
|
|
99
|
+
readonly options: SpellingDictionaryOptions;
|
|
100
|
+
}
|
|
101
|
+
export interface SpellingDictionary extends DictionaryInfo {
|
|
102
|
+
readonly type: string;
|
|
103
|
+
readonly containsNoSuggestWords: boolean;
|
|
104
|
+
has(word: string, options?: HasOptions): boolean;
|
|
105
|
+
/** A more detailed search for a word, might take longer than `has` */
|
|
106
|
+
find(word: string, options?: SearchOptions): FindResult | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Checks if a word is forbidden.
|
|
109
|
+
* @param word - word to check.
|
|
110
|
+
*/
|
|
111
|
+
isForbidden(word: string, ignoreCaseAndAccents?: IgnoreCaseOption): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* No Suggest words are considered correct but will not be listed when
|
|
114
|
+
* suggestions are generated.
|
|
115
|
+
* No Suggest words and "Ignored" words are equivalent. Ignored / no suggest words override forbidden words.
|
|
116
|
+
* @param word - word to check
|
|
117
|
+
* @param options - options
|
|
118
|
+
*/
|
|
119
|
+
isNoSuggestWord(word: string, options: HasOptions): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Generate suggestions for a word.
|
|
122
|
+
* @param word - word
|
|
123
|
+
* @param numSuggestions - max number of suggestions to generate.
|
|
124
|
+
* @param compoundMethod - Default NONE.
|
|
125
|
+
* @param numChanges - Default 5
|
|
126
|
+
* @param ignoreCase - true
|
|
127
|
+
*/
|
|
128
|
+
suggest(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean): SuggestionResult[];
|
|
129
|
+
/**
|
|
130
|
+
* Generate suggestions for a word
|
|
131
|
+
* @param word - word
|
|
132
|
+
* @param suggestOptions - options
|
|
133
|
+
*/
|
|
134
|
+
suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[];
|
|
135
|
+
genSuggestions(collector: SuggestionCollector, suggestOptions: SuggestOptions): void;
|
|
136
|
+
mapWord(word: string): string;
|
|
137
|
+
/**
|
|
138
|
+
* Generates all possible word combinations by applying `repMap`.
|
|
139
|
+
* This acts a bit like brace expansions in globs.
|
|
140
|
+
* @param word - the word to map
|
|
141
|
+
* @returns array of adjusted words.
|
|
142
|
+
*/
|
|
143
|
+
remapWord?: (word: string) => string[];
|
|
144
|
+
readonly size: number;
|
|
145
|
+
readonly isDictionaryCaseSensitive: boolean;
|
|
146
|
+
getErrors?(): Error[];
|
|
147
|
+
}
|
|
148
|
+
export type SuggestArgs = Parameters<SpellingDictionary['suggest']> | Parameters<(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean) => SuggestionResult[]>;
|
|
149
|
+
export declare const defaultOptions: SpellingDictionaryOptions;
|
|
150
|
+
//# sourceMappingURL=SpellingDictionary.d.mts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SearchOptions, SpellingDictionary } from './SpellingDictionary.mjs';
|
|
2
|
+
export interface SpellingDictionaryCollection extends SpellingDictionary {
|
|
3
|
+
readonly type: 'SpellingDictionaryCollection';
|
|
4
|
+
readonly dictionaries: SpellingDictionary[];
|
|
5
|
+
getErrors(): Error[];
|
|
6
|
+
}
|
|
7
|
+
export declare function createCollection(dictionaries: SpellingDictionary[], name: string, source?: string): SpellingDictionaryCollection;
|
|
8
|
+
declare function isWordInAnyDictionary(dicts: SpellingDictionary[], word: string, options: SearchOptions): SpellingDictionary | undefined;
|
|
9
|
+
declare function isWordForbiddenInAnyDictionary(dicts: SpellingDictionary[], word: string, ignoreCase: boolean | undefined): SpellingDictionary | undefined;
|
|
10
|
+
export declare function isSpellingDictionaryCollection(dict: SpellingDictionary): dict is SpellingDictionaryCollection;
|
|
11
|
+
export declare const __testing__: {
|
|
12
|
+
isWordInAnyDictionary: typeof isWordInAnyDictionary;
|
|
13
|
+
isWordForbiddenInAnyDictionary: typeof isWordForbiddenInAnyDictionary;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=SpellingDictionaryCollection.d.mts.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { CASE_INSENSITIVE_PREFIX } from 'cspell-trie-lib';
|
|
2
|
+
import { genSequence } from 'gensequence';
|
|
3
|
+
import { isDefined } from '../util/util.mjs';
|
|
4
|
+
import * as Defaults from './defaults.mjs';
|
|
5
|
+
import { CompoundWordsMethod } from './SpellingDictionary.mjs';
|
|
6
|
+
import { defaultNumSuggestions, hasOptionToSearchOption, suggestArgsToSuggestOptions, suggestionCollector, } from './SpellingDictionaryMethods.mjs';
|
|
7
|
+
function identityString(w) {
|
|
8
|
+
return w;
|
|
9
|
+
}
|
|
10
|
+
class SpellingDictionaryCollectionImpl {
|
|
11
|
+
constructor(dictionaries, name, source) {
|
|
12
|
+
this.dictionaries = dictionaries;
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.options = { weightMap: undefined };
|
|
15
|
+
this.mapWord = identityString;
|
|
16
|
+
this.type = 'SpellingDictionaryCollection';
|
|
17
|
+
this._isNoSuggestWord = (word, options) => {
|
|
18
|
+
if (!this.containsNoSuggestWords)
|
|
19
|
+
return false;
|
|
20
|
+
return !!isNoSuggestWordInAnyDictionary(this.dictionaries, word, options || {});
|
|
21
|
+
};
|
|
22
|
+
this.dictionaries = this.dictionaries.sort((a, b) => b.size - a.size);
|
|
23
|
+
this.source = source || dictionaries.map((d) => d.name).join(', ');
|
|
24
|
+
this.isDictionaryCaseSensitive = this.dictionaries.reduce((a, b) => a || b.isDictionaryCaseSensitive, false);
|
|
25
|
+
this.containsNoSuggestWords = this.dictionaries.reduce((a, b) => a || b.containsNoSuggestWords, false);
|
|
26
|
+
}
|
|
27
|
+
has(word, hasOptions) {
|
|
28
|
+
const options = hasOptionToSearchOption(hasOptions);
|
|
29
|
+
return !!isWordInAnyDictionary(this.dictionaries, word, options) && !this.isForbidden(word);
|
|
30
|
+
}
|
|
31
|
+
find(word, hasOptions) {
|
|
32
|
+
const options = hasOptionToSearchOption(hasOptions);
|
|
33
|
+
return findInAnyDictionary(this.dictionaries, word, options);
|
|
34
|
+
}
|
|
35
|
+
isNoSuggestWord(word, options) {
|
|
36
|
+
return this._isNoSuggestWord(word, options);
|
|
37
|
+
}
|
|
38
|
+
isForbidden(word, ignoreCaseAndAccents) {
|
|
39
|
+
const ignoreCase = ignoreCaseAndAccents ?? Defaults.isForbiddenIgnoreCaseAndAccents;
|
|
40
|
+
return !!this._isForbiddenInDict(word, ignoreCase) && !this.isNoSuggestWord(word, { ignoreCase });
|
|
41
|
+
}
|
|
42
|
+
suggest(...args) {
|
|
43
|
+
const [word] = args;
|
|
44
|
+
const suggestOptions = suggestArgsToSuggestOptions(args);
|
|
45
|
+
return this._suggest(word, suggestOptions);
|
|
46
|
+
}
|
|
47
|
+
_suggest(word, suggestOptions) {
|
|
48
|
+
const { numSuggestions = defaultNumSuggestions, numChanges, ignoreCase, includeTies, timeout } = suggestOptions;
|
|
49
|
+
const prefixNoCase = CASE_INSENSITIVE_PREFIX;
|
|
50
|
+
const filter = (word, _cost) => {
|
|
51
|
+
return ((ignoreCase || word[0] !== prefixNoCase) &&
|
|
52
|
+
!this.isForbidden(word) &&
|
|
53
|
+
!this.isNoSuggestWord(word, suggestOptions));
|
|
54
|
+
};
|
|
55
|
+
const collectorOptions = {
|
|
56
|
+
numSuggestions,
|
|
57
|
+
filter,
|
|
58
|
+
changeLimit: numChanges,
|
|
59
|
+
includeTies,
|
|
60
|
+
ignoreCase,
|
|
61
|
+
timeout,
|
|
62
|
+
};
|
|
63
|
+
const collector = suggestionCollector(word, collectorOptions);
|
|
64
|
+
this.genSuggestions(collector, suggestOptions);
|
|
65
|
+
return collector.suggestions.map((r) => ({ ...r, word: r.word }));
|
|
66
|
+
}
|
|
67
|
+
get size() {
|
|
68
|
+
return this.dictionaries.reduce((a, b) => a + b.size, 0);
|
|
69
|
+
}
|
|
70
|
+
genSuggestions(collector, suggestOptions) {
|
|
71
|
+
const _suggestOptions = { ...suggestOptions };
|
|
72
|
+
const { compoundMethod = CompoundWordsMethod.SEPARATE_WORDS } = suggestOptions;
|
|
73
|
+
_suggestOptions.compoundMethod = this.options.useCompounds ? CompoundWordsMethod.JOIN_WORDS : compoundMethod;
|
|
74
|
+
this.dictionaries.forEach((dict) => dict.genSuggestions(collector, _suggestOptions));
|
|
75
|
+
}
|
|
76
|
+
getErrors() {
|
|
77
|
+
return this.dictionaries.reduce((errors, dict) => errors.concat(dict.getErrors?.() || []), []);
|
|
78
|
+
}
|
|
79
|
+
_isForbiddenInDict(word, ignoreCase) {
|
|
80
|
+
return isWordForbiddenInAnyDictionary(this.dictionaries, word, ignoreCase);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function createCollection(dictionaries, name, source) {
|
|
84
|
+
return new SpellingDictionaryCollectionImpl(dictionaries, name, source);
|
|
85
|
+
}
|
|
86
|
+
function isWordInAnyDictionary(dicts, word, options) {
|
|
87
|
+
return genSequence(dicts).first((dict) => dict.has(word, options));
|
|
88
|
+
}
|
|
89
|
+
function findInAnyDictionary(dicts, word, options) {
|
|
90
|
+
const found = dicts.map((dict) => dict.find(word, options)).filter(isDefined);
|
|
91
|
+
if (!found.length)
|
|
92
|
+
return undefined;
|
|
93
|
+
return found.reduce((a, b) => ({
|
|
94
|
+
found: a.forbidden ? a.found : b.forbidden ? b.found : a.found || b.found,
|
|
95
|
+
forbidden: a.forbidden || b.forbidden,
|
|
96
|
+
noSuggest: a.noSuggest || b.noSuggest,
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
function isNoSuggestWordInAnyDictionary(dicts, word, options) {
|
|
100
|
+
return genSequence(dicts).first((dict) => dict.isNoSuggestWord(word, options));
|
|
101
|
+
}
|
|
102
|
+
function isWordForbiddenInAnyDictionary(dicts, word, ignoreCase) {
|
|
103
|
+
return genSequence(dicts).first((dict) => dict.isForbidden(word, ignoreCase));
|
|
104
|
+
}
|
|
105
|
+
export function isSpellingDictionaryCollection(dict) {
|
|
106
|
+
return dict instanceof SpellingDictionaryCollectionImpl;
|
|
107
|
+
}
|
|
108
|
+
export const __testing__ = {
|
|
109
|
+
isWordInAnyDictionary,
|
|
110
|
+
isWordForbiddenInAnyDictionary,
|
|
111
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { SuggestionCollector, SuggestionResult } from 'cspell-trie-lib';
|
|
2
|
+
import { CompoundWordsMethod, Trie } from 'cspell-trie-lib';
|
|
3
|
+
import type { FindResult, HasOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestOptions } from './SpellingDictionary.mjs';
|
|
4
|
+
export declare class SpellingDictionaryFromTrie implements SpellingDictionary {
|
|
5
|
+
readonly trie: Trie;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly options: SpellingDictionaryOptions;
|
|
8
|
+
readonly source: string;
|
|
9
|
+
static readonly cachedWordsLimit = 50000;
|
|
10
|
+
private _size;
|
|
11
|
+
readonly knownWords: Set<string>;
|
|
12
|
+
readonly unknownWords: Set<string>;
|
|
13
|
+
readonly mapWord: (word: string) => string;
|
|
14
|
+
readonly remapWord: (word: string) => string[];
|
|
15
|
+
readonly type = "SpellingDictionaryFromTrie";
|
|
16
|
+
readonly isDictionaryCaseSensitive: boolean;
|
|
17
|
+
readonly containsNoSuggestWords: boolean;
|
|
18
|
+
private weightMap;
|
|
19
|
+
constructor(trie: Trie, name: string, options: SpellingDictionaryOptions, source?: string, size?: number);
|
|
20
|
+
get size(): number;
|
|
21
|
+
has(word: string, hasOptions?: HasOptions): boolean;
|
|
22
|
+
find(word: string, hasOptions?: HasOptions): FindResult | undefined;
|
|
23
|
+
private resolveOptions;
|
|
24
|
+
private _find;
|
|
25
|
+
private findAnyForm;
|
|
26
|
+
private _findAnyForm;
|
|
27
|
+
isNoSuggestWord(word: string, options?: HasOptions): boolean;
|
|
28
|
+
isForbidden(word: string, _ignoreCaseAndAccents?: boolean): boolean;
|
|
29
|
+
private _isForbidden;
|
|
30
|
+
suggest(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean): SuggestionResult[];
|
|
31
|
+
suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[];
|
|
32
|
+
private _suggest;
|
|
33
|
+
genSuggestions(collector: SuggestionCollector, suggestOptions: SuggestOptions): void;
|
|
34
|
+
getErrors(): Error[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a dictionary from a trie file.
|
|
38
|
+
* @param data - contents of a trie file.
|
|
39
|
+
* @param name - name of dictionary
|
|
40
|
+
* @param source - filename or uri
|
|
41
|
+
* @param options - options.
|
|
42
|
+
* @returns SpellingDictionary
|
|
43
|
+
*/
|
|
44
|
+
export declare function createSpellingDictionaryFromTrieFile(data: Iterable<string> | string, name: string, source: string, options: SpellingDictionaryOptions): SpellingDictionary;
|
|
45
|
+
declare function outerWordForms(word: string, mapWord: (word: string) => string[]): Set<string>;
|
|
46
|
+
export declare const __testing__: {
|
|
47
|
+
outerWordForms: typeof outerWordForms;
|
|
48
|
+
};
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=SpellingDictionaryFromTrie.d.mts.map
|