cspell-dictionary 6.14.3 → 6.15.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/{ForbiddenWordsDictionary.d.ts → FlagWordsDictionary.d.ts} +3 -3
- package/dist/SpellingDictionary/FlagWordsDictionary.js +158 -0
- package/dist/SpellingDictionary/IgnoreWordsDictionary.js +1 -1
- package/dist/SpellingDictionary/SpellingDictionary.d.ts +35 -1
- package/dist/SpellingDictionary/SpellingDictionaryCollection.d.ts +1 -1
- package/dist/SpellingDictionary/SpellingDictionaryCollection.js +34 -8
- package/dist/SpellingDictionary/SpellingDictionaryFromTrie.d.ts +1 -1
- package/dist/SpellingDictionary/SpellingDictionaryFromTrie.js +5 -5
- package/dist/SpellingDictionary/SpellingDictionaryMethods.d.ts +2 -3
- package/dist/SpellingDictionary/Terms/index.d.ts +2 -0
- package/dist/SpellingDictionary/Terms/index.js +3 -0
- package/dist/SpellingDictionary/Terms/terms.d.ts +12 -0
- package/dist/SpellingDictionary/Terms/terms.js +3 -0
- package/dist/SpellingDictionary/Typos/typos.d.ts +7 -7
- package/dist/SpellingDictionary/Typos/typosParser.d.ts +1 -1
- package/dist/SpellingDictionary/Typos/typosParser.js +7 -4
- package/dist/SpellingDictionary/Typos/util.d.ts +11 -0
- package/dist/SpellingDictionary/Typos/util.js +26 -8
- package/dist/SpellingDictionary/TyposDictionary.d.ts +14 -5
- package/dist/SpellingDictionary/TyposDictionary.js +75 -27
- package/dist/SpellingDictionary/defaults.d.ts +2 -1
- package/dist/SpellingDictionary/defaults.js +2 -1
- package/dist/SpellingDictionary/index.d.ts +3 -2
- package/dist/SpellingDictionary/index.js +7 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/util/textMappers.d.ts +3 -0
- package/dist/util/textMappers.js +21 -0
- package/package.json +5 -5
- package/dist/SpellingDictionary/ForbiddenWordsDictionary.js +0 -107
|
@@ -5,7 +5,7 @@ import { SpellingDictionary } from './SpellingDictionary';
|
|
|
5
5
|
* @param name
|
|
6
6
|
* @param source
|
|
7
7
|
* @param options
|
|
8
|
-
* @returns
|
|
8
|
+
* @returns SpellingDictionary
|
|
9
9
|
*/
|
|
10
|
-
export declare function
|
|
11
|
-
//# sourceMappingURL=
|
|
10
|
+
export declare function createFlagWordsDictionary(wordList: readonly string[], name: string, source: string): SpellingDictionary;
|
|
11
|
+
//# sourceMappingURL=FlagWordsDictionary.d.ts.map
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createFlagWordsDictionary = void 0;
|
|
27
|
+
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
28
|
+
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
29
|
+
const createSpellingDictionary_1 = require("./createSpellingDictionary");
|
|
30
|
+
const Defaults = __importStar(require("./defaults"));
|
|
31
|
+
const SpellingDictionaryFromTrie_1 = require("./SpellingDictionaryFromTrie");
|
|
32
|
+
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
33
|
+
const TyposDictionary_1 = require("./TyposDictionary");
|
|
34
|
+
class FlagWordsDictionaryTrie extends SpellingDictionaryFromTrie_1.SpellingDictionaryFromTrie {
|
|
35
|
+
constructor(trie, name, source) {
|
|
36
|
+
super(trie, name, createSpellingDictionary_1.defaultOptions, source);
|
|
37
|
+
this.name = name;
|
|
38
|
+
this.source = source;
|
|
39
|
+
this.containsNoSuggestWords = false;
|
|
40
|
+
this.options = {};
|
|
41
|
+
this.isDictionaryCaseSensitive = true;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A Forbidden word list does not "have" valid words.
|
|
45
|
+
* Therefore it always returns false.
|
|
46
|
+
* @param _word - the word
|
|
47
|
+
* @param _options - options
|
|
48
|
+
* @returns always false
|
|
49
|
+
*/
|
|
50
|
+
has(_word, _options) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
find(word, hasOptions) {
|
|
54
|
+
const f = super.find(word, hasOptions);
|
|
55
|
+
if (!f || !f.forbidden)
|
|
56
|
+
return undefined;
|
|
57
|
+
return f;
|
|
58
|
+
}
|
|
59
|
+
suggest() {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
genSuggestions() {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
class FlagWordsDictionary {
|
|
67
|
+
constructor(name, source, dictTypos, dictTrie) {
|
|
68
|
+
this.name = name;
|
|
69
|
+
this.source = source;
|
|
70
|
+
this.dictTypos = dictTypos;
|
|
71
|
+
this.dictTrie = dictTrie;
|
|
72
|
+
this.containsNoSuggestWords = false;
|
|
73
|
+
this.options = {};
|
|
74
|
+
this.type = 'flag-words';
|
|
75
|
+
this.isDictionaryCaseSensitive = true;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A Forbidden word list does not "have" valid words.
|
|
79
|
+
* Therefore it always returns false.
|
|
80
|
+
* @param word - the word
|
|
81
|
+
* @param options - options
|
|
82
|
+
* @returns always false
|
|
83
|
+
*/
|
|
84
|
+
has(word, options) {
|
|
85
|
+
return this.dictTypos.has(word, options) || this.dictTrie?.has(word, options) || false;
|
|
86
|
+
}
|
|
87
|
+
/** A more detailed search for a word, might take longer than `has` */
|
|
88
|
+
find(word, options) {
|
|
89
|
+
const findTypos = this.dictTypos.find(word, options);
|
|
90
|
+
if (findTypos)
|
|
91
|
+
return findTypos;
|
|
92
|
+
const ignoreCase = options?.ignoreCase ?? Defaults.ignoreCase;
|
|
93
|
+
if (this.dictTypos.isSuggestedWord(word, ignoreCase))
|
|
94
|
+
return undefined;
|
|
95
|
+
return this.dictTrie?.find(word, options);
|
|
96
|
+
}
|
|
97
|
+
isForbidden(word, ignoreCaseAndAccents = Defaults.isForbiddenIgnoreCaseAndAccents) {
|
|
98
|
+
const findResult = this.find(word, { ignoreCase: ignoreCaseAndAccents });
|
|
99
|
+
return findResult?.forbidden || false;
|
|
100
|
+
}
|
|
101
|
+
isNoSuggestWord(word, options) {
|
|
102
|
+
return this.dictTrie?.isNoSuggestWord(word, options) || this.dictTypos.isNoSuggestWord(word, options);
|
|
103
|
+
}
|
|
104
|
+
suggest(...args) {
|
|
105
|
+
const [word] = args;
|
|
106
|
+
const suggestOptions = (0, SpellingDictionaryMethods_1.suggestArgsToSuggestOptions)(args);
|
|
107
|
+
return this.dictTypos.suggest(word, suggestOptions);
|
|
108
|
+
}
|
|
109
|
+
genSuggestions() {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
mapWord(word) {
|
|
113
|
+
return word;
|
|
114
|
+
}
|
|
115
|
+
get size() {
|
|
116
|
+
return this.dictTypos.size + (this.dictTrie?.size || 0);
|
|
117
|
+
}
|
|
118
|
+
getErrors() {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Create a dictionary where all words are to be forbidden.
|
|
124
|
+
* @param wordList - list of words
|
|
125
|
+
* @param name
|
|
126
|
+
* @param source
|
|
127
|
+
* @param options
|
|
128
|
+
* @returns SpellingDictionary
|
|
129
|
+
*/
|
|
130
|
+
function createFlagWordsDictionary(wordList, name, source) {
|
|
131
|
+
const testSpecialCharacters = /[~*+]/;
|
|
132
|
+
const { t: specialWords, f: typoWords } = bisect((0, cspell_trie_lib_1.parseDictionaryLines)(wordList, { stripCaseAndAccents: false }), (line) => testSpecialCharacters.test(line));
|
|
133
|
+
const trieDict = specialWords.size ? buildTrieDict(specialWords, name, source) : undefined;
|
|
134
|
+
const typosDict = (0, TyposDictionary_1.createTyposDictionary)(typoWords, name, source);
|
|
135
|
+
if (!trieDict)
|
|
136
|
+
return typosDict;
|
|
137
|
+
return new FlagWordsDictionary(name, source, typosDict, trieDict);
|
|
138
|
+
}
|
|
139
|
+
exports.createFlagWordsDictionary = createFlagWordsDictionary;
|
|
140
|
+
const regExpCleanIgnore = /^(!!)+/;
|
|
141
|
+
function buildTrieDict(words, name, source) {
|
|
142
|
+
const trie = (0, cspell_trie_lib_1.buildTrieFast)((0, sync_1.pipe)(words, (0, sync_1.opMap)((w) => '!' + w), (0, sync_1.opMap)((w) => w.replace(regExpCleanIgnore, ''))));
|
|
143
|
+
return new FlagWordsDictionaryTrie(trie, name, source);
|
|
144
|
+
}
|
|
145
|
+
function bisect(values, predicate) {
|
|
146
|
+
const t = new Set();
|
|
147
|
+
const f = new Set();
|
|
148
|
+
for (const v of values) {
|
|
149
|
+
if (predicate(v)) {
|
|
150
|
+
t.add(v);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
f.add(v);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return { t, f };
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=FlagWordsDictionary.js.map
|
|
@@ -72,7 +72,7 @@ class IgnoreWordsDictionary {
|
|
|
72
72
|
return { found: nWord, forbidden: false, noSuggest: true };
|
|
73
73
|
return (this.dictNonStrict.has(lcWord) && { found: lcWord, forbidden: false, noSuggest: true }) || undefined;
|
|
74
74
|
}
|
|
75
|
-
isForbidden(_word) {
|
|
75
|
+
isForbidden(_word, _ignoreCase) {
|
|
76
76
|
return false;
|
|
77
77
|
}
|
|
78
78
|
isNoSuggestWord(word, options) {
|
|
@@ -2,7 +2,15 @@ import type { ReplaceMap, DictionaryInformation } from '@cspell/cspell-types';
|
|
|
2
2
|
import type { CompoundWordsMethod, SuggestionCollector, SuggestionResult, WeightMap } from 'cspell-trie-lib';
|
|
3
3
|
export { CompoundWordsMethod, SuggestionCollector, SuggestionResult } from 'cspell-trie-lib';
|
|
4
4
|
export interface SearchOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Legacy compounds have been deprecated.
|
|
7
|
+
*
|
|
8
|
+
* @deprecated
|
|
9
|
+
*/
|
|
5
10
|
useCompounds?: boolean | number | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Ignore Case and Accents
|
|
13
|
+
*/
|
|
6
14
|
ignoreCase?: boolean | undefined;
|
|
7
15
|
}
|
|
8
16
|
export interface SuggestOptions {
|
|
@@ -45,6 +53,7 @@ export interface FindResult {
|
|
|
45
53
|
noSuggest: boolean;
|
|
46
54
|
}
|
|
47
55
|
export type HasOptions = SearchOptions;
|
|
56
|
+
export type IgnoreCaseOption = boolean;
|
|
48
57
|
export interface SpellingDictionaryOptions {
|
|
49
58
|
repMap?: ReplaceMap;
|
|
50
59
|
/**
|
|
@@ -94,9 +103,33 @@ export interface SpellingDictionary extends DictionaryInfo {
|
|
|
94
103
|
has(word: string, options?: HasOptions): boolean;
|
|
95
104
|
/** A more detailed search for a word, might take longer than `has` */
|
|
96
105
|
find(word: string, options?: SearchOptions): FindResult | undefined;
|
|
97
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Checks if a word is forbidden.
|
|
108
|
+
* @param word - word to check.
|
|
109
|
+
*/
|
|
110
|
+
isForbidden(word: string, ignoreCaseAndAccents?: IgnoreCaseOption): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* No Suggest words are considered correct but will not be listed when
|
|
113
|
+
* suggestions are generated.
|
|
114
|
+
* No Suggest words and "Ignored" words are equivalent. Ignored / no suggest words override forbidden words.
|
|
115
|
+
* @param word - word to check
|
|
116
|
+
* @param options - options
|
|
117
|
+
*/
|
|
98
118
|
isNoSuggestWord(word: string, options: HasOptions): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Generate suggestions for a word.
|
|
121
|
+
* @param word - word
|
|
122
|
+
* @param numSuggestions - max number of suggestions to generate.
|
|
123
|
+
* @param compoundMethod - Default NONE.
|
|
124
|
+
* @param numChanges - Default 5
|
|
125
|
+
* @param ignoreCase - true
|
|
126
|
+
*/
|
|
99
127
|
suggest(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean): SuggestionResult[];
|
|
128
|
+
/**
|
|
129
|
+
* Generate suggestions for a word
|
|
130
|
+
* @param word - word
|
|
131
|
+
* @param suggestOptions - options
|
|
132
|
+
*/
|
|
100
133
|
suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[];
|
|
101
134
|
genSuggestions(collector: SuggestionCollector, suggestOptions: SuggestOptions): void;
|
|
102
135
|
mapWord(word: string): string;
|
|
@@ -104,4 +137,5 @@ export interface SpellingDictionary extends DictionaryInfo {
|
|
|
104
137
|
readonly isDictionaryCaseSensitive: boolean;
|
|
105
138
|
getErrors?(): Error[];
|
|
106
139
|
}
|
|
140
|
+
export type SuggestArgs = Parameters<SpellingDictionary['suggest']> | Parameters<(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean) => SuggestionResult[]>;
|
|
107
141
|
//# sourceMappingURL=SpellingDictionary.d.ts.map
|
|
@@ -6,7 +6,7 @@ export interface SpellingDictionaryCollection extends SpellingDictionary {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function createCollection(dictionaries: SpellingDictionary[], name: string): SpellingDictionaryCollection;
|
|
8
8
|
declare function isWordInAnyDictionary(dicts: SpellingDictionary[], word: string, options: SearchOptions): SpellingDictionary | undefined;
|
|
9
|
-
declare function isWordForbiddenInAnyDictionary(dicts: SpellingDictionary[], word: string): SpellingDictionary | undefined;
|
|
9
|
+
declare function isWordForbiddenInAnyDictionary(dicts: SpellingDictionary[], word: string, ignoreCase: boolean | undefined): SpellingDictionary | undefined;
|
|
10
10
|
export declare function isSpellingDictionaryCollection(dict: SpellingDictionary): dict is SpellingDictionaryCollection;
|
|
11
11
|
export declare const __testing__: {
|
|
12
12
|
isWordInAnyDictionary: typeof isWordInAnyDictionary;
|
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.__testing__ = exports.isSpellingDictionaryCollection = exports.createCollection = void 0;
|
|
4
27
|
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
28
|
const gensequence_1 = require("gensequence");
|
|
6
|
-
const util_1 = require("../util/util");
|
|
7
29
|
const clean_1 = require("../util/clean");
|
|
30
|
+
const util_1 = require("../util/util");
|
|
31
|
+
const Defaults = __importStar(require("./defaults"));
|
|
8
32
|
const SpellingDictionary_1 = require("./SpellingDictionary");
|
|
9
33
|
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
10
34
|
function identityString(w) {
|
|
@@ -17,7 +41,6 @@ class SpellingDictionaryCollectionImpl {
|
|
|
17
41
|
this.options = { weightMap: undefined };
|
|
18
42
|
this.mapWord = identityString;
|
|
19
43
|
this.type = 'SpellingDictionaryCollection';
|
|
20
|
-
this._isForbiddenInDict = (word) => isWordForbiddenInAnyDictionary(this.dictionaries, word);
|
|
21
44
|
this._isNoSuggestWord = (word, options) => {
|
|
22
45
|
if (!this.containsNoSuggestWords)
|
|
23
46
|
return false;
|
|
@@ -34,14 +57,14 @@ class SpellingDictionaryCollectionImpl {
|
|
|
34
57
|
}
|
|
35
58
|
find(word, hasOptions) {
|
|
36
59
|
const options = (0, SpellingDictionaryMethods_1.hasOptionToSearchOption)(hasOptions);
|
|
37
|
-
|
|
38
|
-
return { found, forbidden, noSuggest };
|
|
60
|
+
return findInAnyDictionary(this.dictionaries, word, options);
|
|
39
61
|
}
|
|
40
62
|
isNoSuggestWord(word, options) {
|
|
41
63
|
return this._isNoSuggestWord(word, options);
|
|
42
64
|
}
|
|
43
|
-
isForbidden(word) {
|
|
44
|
-
|
|
65
|
+
isForbidden(word, ignoreCaseAndAccents) {
|
|
66
|
+
const ignoreCase = ignoreCaseAndAccents ?? Defaults.isForbiddenIgnoreCaseAndAccents;
|
|
67
|
+
return !!this._isForbiddenInDict(word, ignoreCase) && !this.isNoSuggestWord(word, { ignoreCase });
|
|
45
68
|
}
|
|
46
69
|
suggest(...args) {
|
|
47
70
|
const [word] = args;
|
|
@@ -79,6 +102,9 @@ class SpellingDictionaryCollectionImpl {
|
|
|
79
102
|
getErrors() {
|
|
80
103
|
return this.dictionaries.reduce((errors, dict) => errors.concat(dict.getErrors?.() || []), []);
|
|
81
104
|
}
|
|
105
|
+
_isForbiddenInDict(word, ignoreCase) {
|
|
106
|
+
return isWordForbiddenInAnyDictionary(this.dictionaries, word, ignoreCase);
|
|
107
|
+
}
|
|
82
108
|
}
|
|
83
109
|
function createCollection(dictionaries, name) {
|
|
84
110
|
return new SpellingDictionaryCollectionImpl(dictionaries, name);
|
|
@@ -100,8 +126,8 @@ function findInAnyDictionary(dicts, word, options) {
|
|
|
100
126
|
function isNoSuggestWordInAnyDictionary(dicts, word, options) {
|
|
101
127
|
return (0, gensequence_1.genSequence)(dicts).first((dict) => dict.isNoSuggestWord(word, options));
|
|
102
128
|
}
|
|
103
|
-
function isWordForbiddenInAnyDictionary(dicts, word) {
|
|
104
|
-
return (0, gensequence_1.genSequence)(dicts).first((dict) => dict.isForbidden(word));
|
|
129
|
+
function isWordForbiddenInAnyDictionary(dicts, word, ignoreCase) {
|
|
130
|
+
return (0, gensequence_1.genSequence)(dicts).first((dict) => dict.isForbidden(word, ignoreCase));
|
|
105
131
|
}
|
|
106
132
|
function isSpellingDictionaryCollection(dict) {
|
|
107
133
|
return dict instanceof SpellingDictionaryCollectionImpl;
|
|
@@ -24,7 +24,7 @@ export declare class SpellingDictionaryFromTrie implements SpellingDictionary {
|
|
|
24
24
|
private findAnyForm;
|
|
25
25
|
private _findAnyForm;
|
|
26
26
|
isNoSuggestWord(word: string, options?: HasOptions): boolean;
|
|
27
|
-
isForbidden(word: string): boolean;
|
|
27
|
+
isForbidden(word: string, _ignoreCaseAndAccents?: boolean): boolean;
|
|
28
28
|
private _isForbidden;
|
|
29
29
|
suggest(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean): SuggestionResult[];
|
|
30
30
|
suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[];
|
|
@@ -24,13 +24,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.__testing__ = exports.createSpellingDictionaryFromTrieFile = exports.SpellingDictionaryFromTrie = void 0;
|
|
27
|
+
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
27
28
|
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
28
|
-
const repMap_1 = require("../util/repMap");
|
|
29
|
-
const clean_1 = require("../util/clean");
|
|
30
|
-
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
31
29
|
const AutoCache_1 = require("../util/AutoCache");
|
|
32
|
-
const
|
|
30
|
+
const clean_1 = require("../util/clean");
|
|
31
|
+
const repMap_1 = require("../util/repMap");
|
|
33
32
|
const Defaults = __importStar(require("./defaults"));
|
|
33
|
+
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
34
34
|
const findWordOptionsCaseSensitive = Object.freeze({ caseSensitive: true });
|
|
35
35
|
const findWordOptionsNotCaseSensitive = Object.freeze({ caseSensitive: false });
|
|
36
36
|
class SpellingDictionaryFromTrie {
|
|
@@ -124,7 +124,7 @@ class SpellingDictionaryFromTrie {
|
|
|
124
124
|
isNoSuggestWord(word, options) {
|
|
125
125
|
return this.containsNoSuggestWords ? this.has(word, options) : false;
|
|
126
126
|
}
|
|
127
|
-
isForbidden(word) {
|
|
127
|
+
isForbidden(word, _ignoreCaseAndAccents) {
|
|
128
128
|
return this._isForbidden(word);
|
|
129
129
|
}
|
|
130
130
|
suggest(...args) {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { DictionaryInformation } from '@cspell/cspell-types';
|
|
2
|
-
import {
|
|
3
|
-
import { HasOptions, SearchOptions,
|
|
2
|
+
import { SuggestionResult, WeightMap } from 'cspell-trie-lib';
|
|
3
|
+
import { HasOptions, SearchOptions, SuggestArgs, SuggestOptions } from './SpellingDictionary';
|
|
4
4
|
export { impersonateCollector, suggestionCollector } from 'cspell-trie-lib';
|
|
5
5
|
export type FilterSuggestionsPredicate = (word: SuggestionResult) => boolean;
|
|
6
|
-
export type SuggestArgs = Parameters<SpellingDictionary['suggest']> | Parameters<(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean) => SuggestionResult[]>;
|
|
7
6
|
export declare const defaultNumSuggestions = 10;
|
|
8
7
|
declare function wordSearchFormsArray(word: string, isDictionaryCaseSensitive: boolean, ignoreCase: boolean): string[];
|
|
9
8
|
export declare function wordSearchForms(word: string, isDictionaryCaseSensitive: boolean, ignoreCase: boolean): Set<string>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type TermValueTypoNoSuggestions = false;
|
|
2
|
+
type TermValueTypoSingleSuggestion = string;
|
|
3
|
+
type TermValueTypoMultipleSuggestions = string[];
|
|
4
|
+
export type TermValueTypoWithSuggestions = TermValueTypoSingleSuggestion | TermValueTypoMultipleSuggestions;
|
|
5
|
+
export type TermValueTypo = TermValueTypoWithSuggestions | TermValueTypoNoSuggestions;
|
|
6
|
+
export type TermValueIgnoreWord = null;
|
|
7
|
+
export type TermValueOk = true;
|
|
8
|
+
export type TermsDefValue = TermValueTypo | TermValueIgnoreWord | TermValueOk;
|
|
9
|
+
export type TermsDefKey = string;
|
|
10
|
+
export type TermsDef = Record<TermsDefKey, TermsDefValue>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=terms.d.ts.map
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
type
|
|
2
|
-
type
|
|
3
|
-
type
|
|
4
|
-
export type TyposDefValue =
|
|
5
|
-
export type TyposDefKey =
|
|
1
|
+
import type { TermsDefKey, TermValueTypo, TermValueTypoNoSuggestions, TermValueTypoWithSuggestions } from '../Terms';
|
|
2
|
+
export type TypoValueNoSuggestions = TermValueTypoNoSuggestions;
|
|
3
|
+
export type TypoValueWithSuggestions = TermValueTypoWithSuggestions;
|
|
4
|
+
export type TyposDefValue = TermValueTypo;
|
|
5
|
+
export type TyposDefKey = TermsDefKey;
|
|
6
6
|
/**
|
|
7
7
|
* Typos Definition
|
|
8
8
|
* key - the incorrect word
|
|
9
9
|
* value - the suggestions.
|
|
10
10
|
*/
|
|
11
11
|
export type TyposDef = Record<TyposDefKey, TyposDefValue>;
|
|
12
|
-
type
|
|
12
|
+
type TypoWithNoSuggestions = string;
|
|
13
13
|
type TypoWithSuggestionsArray = [forbidWord: string, ...suggestions: string[]];
|
|
14
14
|
type TypoWithSuggestionsObj = TyposDef;
|
|
15
15
|
type TypoWithSuggestions = TypoWithSuggestionsArray | TypoWithSuggestionsObj;
|
|
16
|
-
export type TypoEntry =
|
|
16
|
+
export type TypoEntry = TypoWithNoSuggestions | TypoWithSuggestions;
|
|
17
17
|
export {};
|
|
18
18
|
//# sourceMappingURL=typos.d.ts.map
|
|
@@ -6,7 +6,7 @@ export declare function sanitizeIntoTypoDef(dirtyDef: TyposDef | Record<string,
|
|
|
6
6
|
* @param entries - entries to process
|
|
7
7
|
* @returns a TyposDef
|
|
8
8
|
*/
|
|
9
|
-
export declare function processEntriesToTyposDef(entries:
|
|
9
|
+
export declare function processEntriesToTyposDef(entries: Iterable<TypoEntry> | TyposDef | Record<string, unknown>): TyposDef;
|
|
10
10
|
/**
|
|
11
11
|
* Tries to parse an entry.
|
|
12
12
|
* @param line - any valid TypoEntry.
|
|
@@ -33,7 +33,7 @@ function trimAndFilter(lines) {
|
|
|
33
33
|
}
|
|
34
34
|
function cleanSugs(rawSugs) {
|
|
35
35
|
const sugs = trimAndFilter(rawSugs);
|
|
36
|
-
return sugs.length === 1 ? sugs[0] : sugs.length ? sugs :
|
|
36
|
+
return sugs.length === 1 ? sugs[0] : sugs.length ? sugs : false;
|
|
37
37
|
}
|
|
38
38
|
function splitSuggestionsValue(value) {
|
|
39
39
|
return cleanSugs(value.split(suggestionsSeparator));
|
|
@@ -55,8 +55,8 @@ function sanitizeIntoTypoDef(dirtyDef) {
|
|
|
55
55
|
def[key] = sugs;
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
|
-
(0, assert_1.default)(value ===
|
|
59
|
-
def[key] =
|
|
58
|
+
(0, assert_1.default)(value === false, 'Unexpected suggestion type.');
|
|
59
|
+
def[key] = false;
|
|
60
60
|
}
|
|
61
61
|
return def;
|
|
62
62
|
}
|
|
@@ -67,7 +67,7 @@ exports.sanitizeIntoTypoDef = sanitizeIntoTypoDef;
|
|
|
67
67
|
* @returns a TyposDef
|
|
68
68
|
*/
|
|
69
69
|
function processEntriesToTyposDef(entries) {
|
|
70
|
-
const def =
|
|
70
|
+
const def = isIterable(entries) ? reduceToTyposDef(entries) : entries;
|
|
71
71
|
const result = sanitizeIntoTypoDef(def);
|
|
72
72
|
(0, assert_1.default)(result);
|
|
73
73
|
return result;
|
|
@@ -120,4 +120,7 @@ function parseTyposFile(content) {
|
|
|
120
120
|
return reduceToTyposDef(lines);
|
|
121
121
|
}
|
|
122
122
|
exports.parseTyposFile = parseTyposFile;
|
|
123
|
+
function isIterable(v) {
|
|
124
|
+
return Symbol.iterator in v;
|
|
125
|
+
}
|
|
123
126
|
//# sourceMappingURL=typosParser.js.map
|
|
@@ -7,6 +7,17 @@ import { TypoEntry, TyposDef, TyposDefKey, TyposDefValue } from './typos';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function appendToDef(def: TyposDef, entry: TypoEntry | undefined): TyposDef;
|
|
9
9
|
export declare function createTyposDef(entries?: Iterable<[TyposDefKey, TyposDefValue]>): TyposDef;
|
|
10
|
+
/**
|
|
11
|
+
* Extract all suggestions.
|
|
12
|
+
* @param typosDef - the def
|
|
13
|
+
* @returns the set of suggestions.
|
|
14
|
+
*/
|
|
10
15
|
export declare function extractAllSuggestions(typosDef: TyposDef): Set<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Extract all words that have been explicitly ignore because they contains the `ignorePrefix`.
|
|
18
|
+
* @param typosDef - the def
|
|
19
|
+
* @param ignorePrefix - prefix
|
|
20
|
+
* @returns set of ignored words with the prefix removed.
|
|
21
|
+
*/
|
|
11
22
|
export declare function extractIgnoreValues(typosDef: TyposDef, ignorePrefix: string): Set<string>;
|
|
12
23
|
//# sourceMappingURL=util.d.ts.map
|
|
@@ -12,7 +12,7 @@ function appendToDef(def, entry) {
|
|
|
12
12
|
if (!entry)
|
|
13
13
|
return def;
|
|
14
14
|
if (typeof entry === 'string') {
|
|
15
|
-
def[entry] =
|
|
15
|
+
def[entry] = false;
|
|
16
16
|
return def;
|
|
17
17
|
}
|
|
18
18
|
if (Array.isArray(entry)) {
|
|
@@ -20,7 +20,7 @@ function appendToDef(def, entry) {
|
|
|
20
20
|
if (!key)
|
|
21
21
|
return def;
|
|
22
22
|
const s = sugs.map((s) => s.trim()).filter((s) => !!s);
|
|
23
|
-
def[key] = !s.length ?
|
|
23
|
+
def[key] = !s.length ? false : s.length === 1 ? s[0] : s;
|
|
24
24
|
return def;
|
|
25
25
|
}
|
|
26
26
|
Object.assign(def, entry);
|
|
@@ -32,26 +32,44 @@ function createTyposDef(entries) {
|
|
|
32
32
|
if (!entries)
|
|
33
33
|
return def;
|
|
34
34
|
for (const [key, value] of entries) {
|
|
35
|
-
def[key] = value;
|
|
35
|
+
def[key] = isDefined(value) ? value : false;
|
|
36
36
|
}
|
|
37
37
|
return def;
|
|
38
38
|
}
|
|
39
39
|
exports.createTyposDef = createTyposDef;
|
|
40
|
+
/**
|
|
41
|
+
* Extract all suggestions.
|
|
42
|
+
* @param typosDef - the def
|
|
43
|
+
* @returns the set of suggestions.
|
|
44
|
+
*/
|
|
40
45
|
function extractAllSuggestions(typosDef) {
|
|
41
|
-
const allSugs = (0, sync_1.pipe)(Object.values(typosDef), (0, sync_1.opFilter)(
|
|
46
|
+
const allSugs = (0, sync_1.pipe)(Object.values(typosDef), (0, sync_1.opFilter)(hasSuggestions), (0, sync_1.opConcatMap)((v) => (Array.isArray(v) ? v : [v])));
|
|
42
47
|
return new Set(allSugs);
|
|
43
48
|
}
|
|
44
49
|
exports.extractAllSuggestions = extractAllSuggestions;
|
|
50
|
+
/**
|
|
51
|
+
* Extract all words that have been explicitly ignore because they contains the `ignorePrefix`.
|
|
52
|
+
* @param typosDef - the def
|
|
53
|
+
* @param ignorePrefix - prefix
|
|
54
|
+
* @returns set of ignored words with the prefix removed.
|
|
55
|
+
*/
|
|
45
56
|
function extractIgnoreValues(typosDef, ignorePrefix) {
|
|
46
|
-
const sugs = extractAllSuggestions(typosDef);
|
|
47
57
|
const pfxLen = ignorePrefix.length;
|
|
48
|
-
|
|
58
|
+
return new Set(Object.keys(typosDef)
|
|
49
59
|
.filter((k) => k.startsWith(ignorePrefix))
|
|
50
|
-
.map((k) => k.slice(pfxLen));
|
|
51
|
-
return (0, sync_1.reduce)(ignoreKeys, (sugs, word) => sugs.add(word), sugs);
|
|
60
|
+
.map((k) => k.slice(pfxLen)));
|
|
52
61
|
}
|
|
53
62
|
exports.extractIgnoreValues = extractIgnoreValues;
|
|
54
63
|
function isDefined(v) {
|
|
55
64
|
return v !== undefined && v !== null;
|
|
56
65
|
}
|
|
66
|
+
function isString(v) {
|
|
67
|
+
return typeof v === 'string';
|
|
68
|
+
}
|
|
69
|
+
function isArray(v) {
|
|
70
|
+
return Array.isArray(v);
|
|
71
|
+
}
|
|
72
|
+
function hasSuggestions(v) {
|
|
73
|
+
return isString(v) || isArray(v);
|
|
74
|
+
}
|
|
57
75
|
//# sourceMappingURL=util.js.map
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import { SpellingDictionary } from './SpellingDictionary';
|
|
1
|
+
import { IgnoreCaseOption, SpellingDictionary } from './SpellingDictionary';
|
|
2
2
|
import { type TypoEntry, type TyposDef } from './Typos';
|
|
3
|
+
export interface TyposDictionary extends SpellingDictionary {
|
|
4
|
+
isForbidden(word: string, ignoreCaseAndAccents?: IgnoreCaseOption): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Determine if the word can appear in a list of suggestions.
|
|
7
|
+
* @param word - word
|
|
8
|
+
* @param ignoreCaseAndAccents - ignore case.
|
|
9
|
+
* @returns true if a word is suggested, otherwise false.
|
|
10
|
+
*/
|
|
11
|
+
isSuggestedWord(word: string, ignoreCaseAndAccents?: IgnoreCaseOption): boolean;
|
|
12
|
+
}
|
|
3
13
|
/**
|
|
4
14
|
* Create a dictionary where all words are to be forbidden.
|
|
5
15
|
* @param entries - list of Typos Entries
|
|
6
|
-
* @param name
|
|
7
|
-
* @param source
|
|
8
|
-
* @param options
|
|
16
|
+
* @param name - name of dictionary
|
|
17
|
+
* @param source - source
|
|
9
18
|
* @returns
|
|
10
19
|
*/
|
|
11
|
-
export declare function createTyposDictionary(entries: string[] | TyposDef |
|
|
20
|
+
export declare function createTyposDictionary(entries: readonly string[] | TyposDef | Iterable<TypoEntry>, name: string, source: string): TyposDictionary;
|
|
12
21
|
//# sourceMappingURL=TyposDictionary.d.ts.map
|
|
@@ -1,21 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.createTyposDictionary = void 0;
|
|
4
27
|
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
28
|
+
const textMappers_1 = require("../util/textMappers");
|
|
29
|
+
const defaults = __importStar(require("./defaults"));
|
|
5
30
|
const Typos_1 = require("./Typos");
|
|
6
31
|
const util_1 = require("./Typos/util");
|
|
7
|
-
|
|
8
|
-
class TyposDictionary {
|
|
32
|
+
class TyposDictionaryImpl {
|
|
9
33
|
constructor(name, source, typosDef, ignoreList) {
|
|
10
34
|
this.name = name;
|
|
11
35
|
this.source = source;
|
|
12
36
|
this.typosDef = typosDef;
|
|
13
|
-
this.containsNoSuggestWords = false;
|
|
14
37
|
this.options = {};
|
|
15
38
|
this.type = 'typos';
|
|
16
39
|
this.isDictionaryCaseSensitive = true;
|
|
17
40
|
this.size = Object.keys(typosDef).length;
|
|
18
|
-
this.
|
|
41
|
+
this.explicitIgnoreWords = (0, util_1.extractIgnoreValues)(typosDef, '!');
|
|
42
|
+
this.suggestions = (0, util_1.extractAllSuggestions)(typosDef);
|
|
43
|
+
this.ignoreWords = new Set((0, sync_1.pipe)(this.explicitIgnoreWords, (0, sync_1.opAppend)(ignoreList || [])));
|
|
44
|
+
this.suggestionsLower = new Set((0, sync_1.pipe)(this.suggestions, textMappers_1.mapperRemoveCaseAndAccents));
|
|
45
|
+
this.containsNoSuggestWords = this.ignoreWords.size > 0;
|
|
19
46
|
}
|
|
20
47
|
/**
|
|
21
48
|
* A Forbidden word list does not "have" valid words.
|
|
@@ -28,32 +55,54 @@ class TyposDictionary {
|
|
|
28
55
|
return false;
|
|
29
56
|
}
|
|
30
57
|
/** A more detailed search for a word, might take longer than `has` */
|
|
31
|
-
find(word,
|
|
32
|
-
const
|
|
33
|
-
|
|
58
|
+
find(word, options) {
|
|
59
|
+
const result = this._findForms(word, options?.ignoreCase ?? defaults.ignoreCase);
|
|
60
|
+
if (result === false)
|
|
61
|
+
return undefined;
|
|
62
|
+
const { found, ignore } = result;
|
|
63
|
+
return { found, forbidden: !ignore, noSuggest: ignore };
|
|
34
64
|
}
|
|
35
|
-
_findForms(word) {
|
|
36
|
-
const f = this._find(word);
|
|
37
|
-
if (f !== false)
|
|
38
|
-
return f;
|
|
65
|
+
_findForms(word, ignoreCaseAndAccents) {
|
|
39
66
|
const lcWord = word.toLowerCase();
|
|
40
|
-
if (
|
|
67
|
+
if (this.ignoreWords.has(word)) {
|
|
68
|
+
return { found: word, ignore: true };
|
|
69
|
+
}
|
|
70
|
+
if (this.suggestions.has(word)) {
|
|
41
71
|
return false;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
72
|
+
}
|
|
73
|
+
if (ignoreCaseAndAccents) {
|
|
74
|
+
if (this.suggestionsLower.has(lcWord)) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (this.ignoreWords.has(lcWord)) {
|
|
78
|
+
return { found: lcWord, ignore: true };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
47
81
|
if (word in this.typosDef)
|
|
48
|
-
return word;
|
|
82
|
+
return { found: word, ignore: false };
|
|
83
|
+
if (lcWord in this.typosDef)
|
|
84
|
+
return { found: lcWord, ignore: false };
|
|
49
85
|
return false;
|
|
50
86
|
}
|
|
51
|
-
isForbidden(word) {
|
|
52
|
-
const found = this._findForms(word);
|
|
53
|
-
return
|
|
87
|
+
isForbidden(word, ignoreCaseAndAccents = defaults.isForbiddenIgnoreCaseAndAccents) {
|
|
88
|
+
const found = this._findForms(word, ignoreCaseAndAccents);
|
|
89
|
+
return found !== false && !found.ignore;
|
|
54
90
|
}
|
|
55
|
-
isNoSuggestWord(
|
|
56
|
-
|
|
91
|
+
isNoSuggestWord(word, options) {
|
|
92
|
+
const result = this.find(word, options);
|
|
93
|
+
return result?.noSuggest ?? false;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Determine if the word can appear in a list of suggestions.
|
|
97
|
+
* @param word - word
|
|
98
|
+
* @param ignoreCaseAndAccents - ignore case.
|
|
99
|
+
* @returns true if a word is suggested, otherwise false.
|
|
100
|
+
*/
|
|
101
|
+
isSuggestedWord(word, ignoreCaseAndAccents = defaults.isForbiddenIgnoreCaseAndAccents) {
|
|
102
|
+
if (this.suggestions.has(word))
|
|
103
|
+
return true;
|
|
104
|
+
const lcWord = word.toLowerCase();
|
|
105
|
+
return ignoreCaseAndAccents && (this.suggestions.has(lcWord) || this.suggestionsLower.has(lcWord));
|
|
57
106
|
}
|
|
58
107
|
suggest(word) {
|
|
59
108
|
return this._suggest(word) || this._suggest(word.toLowerCase()) || [];
|
|
@@ -91,14 +140,13 @@ class TyposDictionary {
|
|
|
91
140
|
/**
|
|
92
141
|
* Create a dictionary where all words are to be forbidden.
|
|
93
142
|
* @param entries - list of Typos Entries
|
|
94
|
-
* @param name
|
|
95
|
-
* @param source
|
|
96
|
-
* @param options
|
|
143
|
+
* @param name - name of dictionary
|
|
144
|
+
* @param source - source
|
|
97
145
|
* @returns
|
|
98
146
|
*/
|
|
99
147
|
function createTyposDictionary(entries, name, source) {
|
|
100
148
|
const def = (0, Typos_1.processEntriesToTyposDef)(entries);
|
|
101
|
-
return new
|
|
149
|
+
return new TyposDictionaryImpl(name, source, def);
|
|
102
150
|
}
|
|
103
151
|
exports.createTyposDictionary = createTyposDictionary;
|
|
104
152
|
//# sourceMappingURL=TyposDictionary.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ignoreCase = void 0;
|
|
3
|
+
exports.isForbiddenIgnoreCaseAndAccents = exports.ignoreCase = void 0;
|
|
4
4
|
exports.ignoreCase = true;
|
|
5
|
+
exports.isForbiddenIgnoreCaseAndAccents = false;
|
|
5
6
|
//# sourceMappingURL=defaults.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { CachingDictionary, createCachingDictionary } from './CachingDictionary';
|
|
2
|
-
export {
|
|
3
|
-
export { createForbiddenWordsDictionary } from './
|
|
2
|
+
export { createFailedToLoadDictionary, createSpellingDictionary } from './createSpellingDictionary';
|
|
3
|
+
export { createFlagWordsDictionary, createFlagWordsDictionary as createForbiddenWordsDictionary, } from './FlagWordsDictionary';
|
|
4
4
|
export { createIgnoreWordsDictionary } from './IgnoreWordsDictionary';
|
|
5
5
|
export type { FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary';
|
|
6
6
|
export { createCollection, SpellingDictionaryCollection } from './SpellingDictionaryCollection';
|
|
7
7
|
export { createSpellingDictionaryFromTrieFile } from './SpellingDictionaryFromTrie';
|
|
8
|
+
export { createTyposDictionary } from './TyposDictionary';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSpellingDictionaryFromTrieFile = exports.createCollection = exports.createIgnoreWordsDictionary = exports.createForbiddenWordsDictionary = exports.
|
|
3
|
+
exports.createTyposDictionary = exports.createSpellingDictionaryFromTrieFile = exports.createCollection = exports.createIgnoreWordsDictionary = exports.createForbiddenWordsDictionary = exports.createFlagWordsDictionary = exports.createSpellingDictionary = exports.createFailedToLoadDictionary = exports.createCachingDictionary = void 0;
|
|
4
4
|
var CachingDictionary_1 = require("./CachingDictionary");
|
|
5
5
|
Object.defineProperty(exports, "createCachingDictionary", { enumerable: true, get: function () { return CachingDictionary_1.createCachingDictionary; } });
|
|
6
6
|
var createSpellingDictionary_1 = require("./createSpellingDictionary");
|
|
7
|
-
Object.defineProperty(exports, "createSpellingDictionary", { enumerable: true, get: function () { return createSpellingDictionary_1.createSpellingDictionary; } });
|
|
8
7
|
Object.defineProperty(exports, "createFailedToLoadDictionary", { enumerable: true, get: function () { return createSpellingDictionary_1.createFailedToLoadDictionary; } });
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
Object.defineProperty(exports, "createSpellingDictionary", { enumerable: true, get: function () { return createSpellingDictionary_1.createSpellingDictionary; } });
|
|
9
|
+
var FlagWordsDictionary_1 = require("./FlagWordsDictionary");
|
|
10
|
+
Object.defineProperty(exports, "createFlagWordsDictionary", { enumerable: true, get: function () { return FlagWordsDictionary_1.createFlagWordsDictionary; } });
|
|
11
|
+
Object.defineProperty(exports, "createForbiddenWordsDictionary", { enumerable: true, get: function () { return FlagWordsDictionary_1.createFlagWordsDictionary; } });
|
|
11
12
|
var IgnoreWordsDictionary_1 = require("./IgnoreWordsDictionary");
|
|
12
13
|
Object.defineProperty(exports, "createIgnoreWordsDictionary", { enumerable: true, get: function () { return IgnoreWordsDictionary_1.createIgnoreWordsDictionary; } });
|
|
13
14
|
var SpellingDictionaryCollection_1 = require("./SpellingDictionaryCollection");
|
|
14
15
|
Object.defineProperty(exports, "createCollection", { enumerable: true, get: function () { return SpellingDictionaryCollection_1.createCollection; } });
|
|
15
16
|
var SpellingDictionaryFromTrie_1 = require("./SpellingDictionaryFromTrie");
|
|
16
17
|
Object.defineProperty(exports, "createSpellingDictionaryFromTrieFile", { enumerable: true, get: function () { return SpellingDictionaryFromTrie_1.createSpellingDictionaryFromTrieFile; } });
|
|
18
|
+
var TyposDictionary_1 = require("./TyposDictionary");
|
|
19
|
+
Object.defineProperty(exports, "createTyposDictionary", { enumerable: true, get: function () { return TyposDictionary_1.createTyposDictionary; } });
|
|
17
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createCachingDictionary, createCollection, createFailedToLoadDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile,
|
|
2
|
-
export type { CachingDictionary, FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary';
|
|
1
|
+
export { createCachingDictionary, createCollection, createFailedToLoadDictionary, createFlagWordsDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, } from './SpellingDictionary';
|
|
2
|
+
export type { CachingDictionary, FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryCollection, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSpellingDictionaryFromTrieFile = exports.createSpellingDictionary = exports.createIgnoreWordsDictionary = exports.createForbiddenWordsDictionary = exports.createFailedToLoadDictionary = exports.createCollection = exports.createCachingDictionary = void 0;
|
|
3
|
+
exports.createSpellingDictionaryFromTrieFile = exports.createSpellingDictionary = exports.createIgnoreWordsDictionary = exports.createForbiddenWordsDictionary = exports.createFlagWordsDictionary = exports.createFailedToLoadDictionary = exports.createCollection = exports.createCachingDictionary = void 0;
|
|
4
4
|
var SpellingDictionary_1 = require("./SpellingDictionary");
|
|
5
5
|
Object.defineProperty(exports, "createCachingDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createCachingDictionary; } });
|
|
6
6
|
Object.defineProperty(exports, "createCollection", { enumerable: true, get: function () { return SpellingDictionary_1.createCollection; } });
|
|
7
7
|
Object.defineProperty(exports, "createFailedToLoadDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createFailedToLoadDictionary; } });
|
|
8
|
+
Object.defineProperty(exports, "createFlagWordsDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createFlagWordsDictionary; } });
|
|
8
9
|
Object.defineProperty(exports, "createForbiddenWordsDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createForbiddenWordsDictionary; } });
|
|
9
10
|
Object.defineProperty(exports, "createIgnoreWordsDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createIgnoreWordsDictionary; } });
|
|
10
11
|
Object.defineProperty(exports, "createSpellingDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createSpellingDictionary; } });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapperRemoveCaseAndAccents = exports.mapperNormalizeNFC = void 0;
|
|
4
|
+
const text_1 = require("./text");
|
|
5
|
+
function* mapperNormalizeNFC(words) {
|
|
6
|
+
for (const word of words) {
|
|
7
|
+
yield word.normalize('NFC');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.mapperNormalizeNFC = mapperNormalizeNFC;
|
|
11
|
+
function* mapperRemoveCaseAndAccents(words) {
|
|
12
|
+
for (const word of words) {
|
|
13
|
+
const lc = word.toLowerCase();
|
|
14
|
+
yield lc;
|
|
15
|
+
const woAccents = (0, text_1.removeAccents)(lc);
|
|
16
|
+
if (lc !== woAccents)
|
|
17
|
+
yield woAccents;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.mapperRemoveCaseAndAccents = mapperRemoveCaseAndAccents;
|
|
21
|
+
//# sourceMappingURL=textMappers.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-dictionary",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.15.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.3"
|
|
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.15.0",
|
|
47
|
+
"@cspell/cspell-types": "6.15.0",
|
|
48
|
+
"cspell-trie-lib": "6.15.0",
|
|
49
49
|
"fast-equals": "^4.0.3",
|
|
50
50
|
"gensequence": "^4.0.2"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "8bbc20a6fabe0b95caafb7dac2035764cc73ba13"
|
|
53
53
|
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createForbiddenWordsDictionary = void 0;
|
|
4
|
-
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
|
-
const createSpellingDictionary_1 = require("./createSpellingDictionary");
|
|
6
|
-
const SpellingDictionaryFromTrie_1 = require("./SpellingDictionaryFromTrie");
|
|
7
|
-
class ForbiddenWordsDictionaryTrie extends SpellingDictionaryFromTrie_1.SpellingDictionaryFromTrie {
|
|
8
|
-
constructor(trie, name, source) {
|
|
9
|
-
super(trie, name, createSpellingDictionary_1.defaultOptions, source);
|
|
10
|
-
this.name = name;
|
|
11
|
-
this.source = source;
|
|
12
|
-
this.containsNoSuggestWords = false;
|
|
13
|
-
this.options = {};
|
|
14
|
-
this.isDictionaryCaseSensitive = true;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* A Forbidden word list does not "have" valid words.
|
|
18
|
-
* Therefore it always returns false.
|
|
19
|
-
* @param _word - the word
|
|
20
|
-
* @param _options - options
|
|
21
|
-
* @returns always false
|
|
22
|
-
*/
|
|
23
|
-
has(_word, _options) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
find(word, hasOptions) {
|
|
27
|
-
const f = super.find(word, hasOptions);
|
|
28
|
-
if (!f || !f.forbidden)
|
|
29
|
-
return undefined;
|
|
30
|
-
return f;
|
|
31
|
-
}
|
|
32
|
-
suggest() {
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
genSuggestions() {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
class ForbiddenWordsDictionary {
|
|
40
|
-
constructor(name, source, words) {
|
|
41
|
-
this.name = name;
|
|
42
|
-
this.source = source;
|
|
43
|
-
this.containsNoSuggestWords = false;
|
|
44
|
-
this.options = {};
|
|
45
|
-
this.type = 'forbidden';
|
|
46
|
-
this.isDictionaryCaseSensitive = true;
|
|
47
|
-
this.dict = new Set(words);
|
|
48
|
-
this.dictIgnore = new Set(words.filter((w) => w.startsWith('!')).map((w) => w.slice(1)));
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* A Forbidden word list does not "have" valid words.
|
|
52
|
-
* Therefore it always returns false.
|
|
53
|
-
* @param _word - the word
|
|
54
|
-
* @param _options - options
|
|
55
|
-
* @returns always false
|
|
56
|
-
*/
|
|
57
|
-
has(_word, _options) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
/** A more detailed search for a word, might take longer than `has` */
|
|
61
|
-
find(word, _options) {
|
|
62
|
-
const forbidden = this.isForbidden(word);
|
|
63
|
-
return forbidden ? { found: word, forbidden, noSuggest: false } : undefined;
|
|
64
|
-
}
|
|
65
|
-
isForbidden(word) {
|
|
66
|
-
return (this.dict.has(word) || this.dict.has(word.toLowerCase())) && !this.dictIgnore.has(word);
|
|
67
|
-
}
|
|
68
|
-
isNoSuggestWord(_word, _options) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
suggest() {
|
|
72
|
-
return [];
|
|
73
|
-
}
|
|
74
|
-
genSuggestions() {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
mapWord(word) {
|
|
78
|
-
return word;
|
|
79
|
-
}
|
|
80
|
-
get size() {
|
|
81
|
-
return this.dict.size;
|
|
82
|
-
}
|
|
83
|
-
getErrors() {
|
|
84
|
-
return [];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Create a dictionary where all words are to be forbidden.
|
|
89
|
-
* @param wordList - list of words
|
|
90
|
-
* @param name
|
|
91
|
-
* @param source
|
|
92
|
-
* @param options
|
|
93
|
-
* @returns
|
|
94
|
-
*/
|
|
95
|
-
function createForbiddenWordsDictionary(wordList, name, source) {
|
|
96
|
-
const testSpecialCharacters = /[~*+]/;
|
|
97
|
-
const regExpCleanIgnore = /^(!!)+/;
|
|
98
|
-
const words = [...(0, cspell_trie_lib_1.parseDictionaryLines)(wordList, { stripCaseAndAccents: false })];
|
|
99
|
-
const hasSpecial = words.findIndex((word) => testSpecialCharacters.test(word)) >= 0;
|
|
100
|
-
if (hasSpecial) {
|
|
101
|
-
const trie = (0, cspell_trie_lib_1.buildTrieFast)(words.map((w) => '!' + w).map((w) => w.replace(regExpCleanIgnore, '')));
|
|
102
|
-
return new ForbiddenWordsDictionaryTrie(trie, name, source);
|
|
103
|
-
}
|
|
104
|
-
return new ForbiddenWordsDictionary(name, source, words);
|
|
105
|
-
}
|
|
106
|
-
exports.createForbiddenWordsDictionary = createForbiddenWordsDictionary;
|
|
107
|
-
//# sourceMappingURL=ForbiddenWordsDictionary.js.map
|