cspell-lib 6.11.1 → 6.12.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/Dictionaries.d.ts +1 -1
- package/dist/SpellingDictionary/Dictionaries.js +6 -9
- package/dist/SpellingDictionary/DictionaryController/DictionaryLoader.d.ts +1 -1
- package/dist/SpellingDictionary/DictionaryController/DictionaryLoader.js +9 -10
- package/dist/SpellingDictionary/DictionaryLoader.d.ts +1 -1
- package/dist/SpellingDictionary/SpellingDictionary.d.ts +4 -4
- package/dist/SpellingDictionary/SpellingDictionary.js +2 -6
- package/dist/textValidation/textValidator.d.ts +1 -1
- package/package.json +10 -10
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/SpellingDictionary.d.ts +0 -4
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/SpellingDictionary.js +0 -6
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/SpellingDictionaryCollection.d.ts +0 -35
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/SpellingDictionaryCollection.js +0 -116
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/SpellingDictionaryFromTrie.d.ts +0 -36
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/SpellingDictionaryFromTrie.js +0 -150
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/SpellingDictionaryMethods.d.ts +0 -29
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/SpellingDictionaryMethods.js +0 -114
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/charset.d.ts +0 -3
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/charset.js +0 -16
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/createSpellingDictionary.d.ts +0 -8
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/createSpellingDictionary.js +0 -90
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/index.d.ts +0 -11
- package/dist/SpellingDictionary/SpellingDictionaryLibOld/index.js +0 -28
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { SpellingDictionary, SpellingDictionaryCollection } from 'cspell-dictionary';
|
|
1
2
|
import { CSpellSettingsInternal, DictionaryDefinitionInternal } from '../Models/CSpellSettingsInternalDef';
|
|
2
|
-
import { SpellingDictionary, SpellingDictionaryCollection } from './SpellingDictionary';
|
|
3
3
|
export declare function loadDictionaryDefs(defsToLoad: DictionaryDefinitionInternal[]): Promise<SpellingDictionary>[];
|
|
4
4
|
export declare function loadDictionaryDefsSync(defsToLoad: DictionaryDefinitionInternal[]): SpellingDictionary[];
|
|
5
5
|
export declare function refreshDictionaryCache(maxAge?: number): Promise<void>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDictionaryInternalSync = exports.getDictionaryInternal = exports.refreshDictionaryCache = exports.loadDictionaryDefsSync = exports.loadDictionaryDefs = void 0;
|
|
4
|
+
const cspell_dictionary_1 = require("cspell-dictionary");
|
|
4
5
|
const DictionarySettings_1 = require("../Settings/DictionarySettings");
|
|
5
6
|
const util_1 = require("../util/util");
|
|
6
7
|
const DictionaryLoader_1 = require("./DictionaryLoader");
|
|
7
|
-
const SpellingDictionary_1 = require("./SpellingDictionary");
|
|
8
8
|
function loadDictionaryDefs(defsToLoad) {
|
|
9
9
|
return defsToLoad.map(DictionaryLoader_1.loadDictionary);
|
|
10
10
|
}
|
|
@@ -30,21 +30,18 @@ function getDictionaryInternalSync(settings) {
|
|
|
30
30
|
exports.getDictionaryInternalSync = getDictionaryInternalSync;
|
|
31
31
|
function _getDictionaryInternal(settings, spellDictionaries) {
|
|
32
32
|
const { words = emptyWords, userWords = emptyWords, flagWords = emptyWords, ignoreWords = emptyWords } = settings;
|
|
33
|
-
const
|
|
34
|
-
const settingsWordsDictionary = createSpellingDictionary(words, '[words]', 'From Settings `words`', {
|
|
33
|
+
const settingsWordsDictionary = (0, cspell_dictionary_1.createSpellingDictionary)(words, '[words]', 'From Settings `words`', {
|
|
35
34
|
caseSensitive: true,
|
|
36
35
|
weightMap: undefined,
|
|
37
36
|
});
|
|
38
37
|
const settingsUserWordsDictionary = userWords.length
|
|
39
|
-
? createSpellingDictionary(userWords, '[userWords]', 'From Settings `userWords`', {
|
|
38
|
+
? (0, cspell_dictionary_1.createSpellingDictionary)(userWords, '[userWords]', 'From Settings `userWords`', {
|
|
40
39
|
caseSensitive: true,
|
|
41
40
|
weightMap: undefined,
|
|
42
41
|
})
|
|
43
42
|
: undefined;
|
|
44
|
-
const ignoreWordsDictionary = createIgnoreWordsDictionary(ignoreWords, '[ignoreWords]', 'From Settings `ignoreWords`');
|
|
45
|
-
const flagWordsDictionary = createForbiddenWordsDictionary(flagWords, '[flagWords]', 'From Settings `flagWords`'
|
|
46
|
-
weightMap: undefined,
|
|
47
|
-
});
|
|
43
|
+
const ignoreWordsDictionary = (0, cspell_dictionary_1.createIgnoreWordsDictionary)(ignoreWords, '[ignoreWords]', 'From Settings `ignoreWords`');
|
|
44
|
+
const flagWordsDictionary = (0, cspell_dictionary_1.createForbiddenWordsDictionary)(flagWords, '[flagWords]', 'From Settings `flagWords`');
|
|
48
45
|
const dictionaries = [
|
|
49
46
|
...spellDictionaries,
|
|
50
47
|
settingsWordsDictionary,
|
|
@@ -52,6 +49,6 @@ function _getDictionaryInternal(settings, spellDictionaries) {
|
|
|
52
49
|
ignoreWordsDictionary,
|
|
53
50
|
flagWordsDictionary,
|
|
54
51
|
].filter(util_1.isDefined);
|
|
55
|
-
return createCollection(dictionaries, 'dictionary collection');
|
|
52
|
+
return (0, cspell_dictionary_1.createCollection)(dictionaries, 'dictionary collection');
|
|
56
53
|
}
|
|
57
54
|
//# sourceMappingURL=Dictionaries.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { SpellingDictionary } from 'cspell-dictionary';
|
|
1
2
|
import { CSpellIO } from 'cspell-io';
|
|
2
3
|
import { DictionaryDefinitionInternal } from '../../Models/CSpellSettingsInternalDef';
|
|
3
|
-
import { SpellingDictionary } from '../SpellingDictionaryLibOld/SpellingDictionary';
|
|
4
4
|
export declare type LoadOptions = DictionaryDefinitionInternal;
|
|
5
5
|
export declare class DictionaryLoader {
|
|
6
6
|
private cspellIO;
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DictionaryLoader = void 0;
|
|
4
4
|
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
5
|
+
const cspell_dictionary_1 = require("cspell-dictionary");
|
|
5
6
|
const errors_1 = require("../../util/errors");
|
|
6
|
-
const createSpellingDictionary_1 = require("../SpellingDictionaryLibOld/createSpellingDictionary");
|
|
7
7
|
const SpellingDictionaryError_1 = require("../SpellingDictionaryError");
|
|
8
|
-
const SpellingDictionaryFromTrie_1 = require("../SpellingDictionaryLibOld/SpellingDictionaryFromTrie");
|
|
9
8
|
const MAX_AGE = 10000;
|
|
10
9
|
const loaders = {
|
|
11
10
|
S: loadSimpleWordList,
|
|
@@ -98,7 +97,7 @@ class DictionaryLoader {
|
|
|
98
97
|
}
|
|
99
98
|
loadEntry(uri, options, now = Date.now()) {
|
|
100
99
|
options = this.normalizeOptions(uri, options);
|
|
101
|
-
const pDictionary = load(this.reader, uri, options).catch((e) => (0,
|
|
100
|
+
const pDictionary = load(this.reader, uri, options).catch((e) => (0, cspell_dictionary_1.createFailedToLoadDictionary)(options.name, uri, new SpellingDictionaryError_1.SpellingDictionaryLoadError(uri, options, e, 'failed to load'), options));
|
|
102
101
|
const pStat = this.getStat(uri);
|
|
103
102
|
const pending = Promise.all([pDictionary, pStat]);
|
|
104
103
|
const sig = now + Math.random();
|
|
@@ -141,7 +140,7 @@ class DictionaryLoader {
|
|
|
141
140
|
}
|
|
142
141
|
catch (e) {
|
|
143
142
|
const error = (0, errors_1.toError)(e);
|
|
144
|
-
const dictionary = (0,
|
|
143
|
+
const dictionary = (0, cspell_dictionary_1.createFailedToLoadDictionary)(options.name, uri, new SpellingDictionaryError_1.SpellingDictionaryLoadError(uri, options, error, 'failed to load'), options);
|
|
145
144
|
const pending = Promise.resolve([dictionary, stat]);
|
|
146
145
|
return {
|
|
147
146
|
uri,
|
|
@@ -236,7 +235,7 @@ function _legacyWordListSync(lines, filename, options) {
|
|
|
236
235
|
(0, sync_1.opMap)((line) => line.replace(/#.*/g, '')),
|
|
237
236
|
// Split on everything else
|
|
238
237
|
(0, sync_1.opConcatMap)((line) => line.split(/[^\w\p{L}\p{M}'’]+/gu)), (0, sync_1.opFilter)((word) => !!word));
|
|
239
|
-
return (0,
|
|
238
|
+
return (0, cspell_dictionary_1.createSpellingDictionary)(words, options.name, filename, options);
|
|
240
239
|
}
|
|
241
240
|
async function wordsPerLineWordList(readLines, filename, options) {
|
|
242
241
|
const lines = await readLines(filename);
|
|
@@ -252,22 +251,22 @@ function _wordsPerLineWordList(lines, filename, options) {
|
|
|
252
251
|
(0, sync_1.opMap)((line) => line.replace(/#.*/g, '')),
|
|
253
252
|
// Split on everything else
|
|
254
253
|
(0, sync_1.opConcatMap)((line) => line.split(/\s+/gu)), (0, sync_1.opFilter)((word) => !!word));
|
|
255
|
-
return (0,
|
|
254
|
+
return (0, cspell_dictionary_1.createSpellingDictionary)(words, options.name, filename, options);
|
|
256
255
|
}
|
|
257
256
|
async function loadSimpleWordList(reader, filename, options) {
|
|
258
257
|
const lines = await reader(filename);
|
|
259
|
-
return (0,
|
|
258
|
+
return (0, cspell_dictionary_1.createSpellingDictionary)(lines, options.name, filename, options);
|
|
260
259
|
}
|
|
261
260
|
function loadSimpleWordListSync(readLinesSync, filename, options) {
|
|
262
261
|
const lines = readLinesSync(filename);
|
|
263
|
-
return (0,
|
|
262
|
+
return (0, cspell_dictionary_1.createSpellingDictionary)(lines, options.name, filename, options);
|
|
264
263
|
}
|
|
265
264
|
async function loadTrie(readLines, filename, options) {
|
|
266
265
|
const lines = await readLines(filename);
|
|
267
|
-
return (0,
|
|
266
|
+
return (0, cspell_dictionary_1.createSpellingDictionaryFromTrieFile)(lines, options.name, filename, options);
|
|
268
267
|
}
|
|
269
268
|
function loadTrieSync(readLinesSync, filename, options) {
|
|
270
269
|
const lines = readLinesSync(filename);
|
|
271
|
-
return (0,
|
|
270
|
+
return (0, cspell_dictionary_1.createSpellingDictionaryFromTrieFile)(lines, options.name, filename, options);
|
|
272
271
|
}
|
|
273
272
|
//# sourceMappingURL=DictionaryLoader.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CSpellIO } from 'cspell-io';
|
|
2
2
|
import { DictionaryDefinitionInternal } from '../Models/CSpellSettingsInternalDef';
|
|
3
3
|
import { DictionaryLoader } from './DictionaryController';
|
|
4
|
-
import { SpellingDictionary } from '
|
|
4
|
+
import { SpellingDictionary } from 'cspell-dictionary';
|
|
5
5
|
export type { LoadOptions } from './DictionaryController';
|
|
6
6
|
export declare function getDictionaryLoader(cspellIO?: CSpellIO): DictionaryLoader;
|
|
7
7
|
export declare function loadDictionary(def: DictionaryDefinitionInternal): Promise<SpellingDictionary>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import * as cspellDictModule from 'cspell-dictionary';
|
|
2
|
-
import { SpellingDictionaryLibOld } from './SpellingDictionaryLibOld';
|
|
3
2
|
export { CompoundWordsMethod } from 'cspell-trie-lib';
|
|
4
3
|
declare const SpellingDictionaryModule: {
|
|
5
4
|
readonly createCollection: typeof cspellDictModule.createCollection;
|
|
6
5
|
readonly createForbiddenWordsDictionary: typeof cspellDictModule.createForbiddenWordsDictionary;
|
|
7
6
|
readonly createSpellingDictionary: typeof cspellDictModule.createSpellingDictionary;
|
|
8
7
|
readonly createIgnoreWordsDictionary: typeof cspellDictModule.createIgnoreWordsDictionary;
|
|
8
|
+
readonly createSpellingDictionaryFromTrieFile: typeof cspellDictModule.createSpellingDictionaryFromTrieFile;
|
|
9
9
|
};
|
|
10
|
-
declare type SpellDictInterface = typeof SpellingDictionaryModule
|
|
10
|
+
declare type SpellDictInterface = typeof SpellingDictionaryModule;
|
|
11
11
|
export type { FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryCollection, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from 'cspell-dictionary';
|
|
12
12
|
export declare function getSpellDictInterface(): SpellDictInterface;
|
|
13
|
-
export declare const createSpellingDictionary: typeof
|
|
14
|
-
export declare const createCollection: typeof
|
|
13
|
+
export declare const createSpellingDictionary: typeof cspellDictModule.createSpellingDictionary;
|
|
14
|
+
export declare const createCollection: typeof cspellDictModule.createCollection;
|
|
15
15
|
//# sourceMappingURL=SpellingDictionary.d.ts.map
|
|
@@ -25,8 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.createCollection = exports.createSpellingDictionary = exports.getSpellDictInterface = exports.CompoundWordsMethod = void 0;
|
|
27
27
|
const cspellDictModule = __importStar(require("cspell-dictionary"));
|
|
28
|
-
const FeatureFlags_1 = require("../FeatureFlags");
|
|
29
|
-
const SpellingDictionaryLibOld_1 = require("./SpellingDictionaryLibOld");
|
|
30
28
|
var cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
31
29
|
Object.defineProperty(exports, "CompoundWordsMethod", { enumerable: true, get: function () { return cspell_trie_lib_1.CompoundWordsMethod; } });
|
|
32
30
|
const SpellingDictionaryModule = {
|
|
@@ -34,12 +32,10 @@ const SpellingDictionaryModule = {
|
|
|
34
32
|
createForbiddenWordsDictionary: cspellDictModule.createForbiddenWordsDictionary,
|
|
35
33
|
createSpellingDictionary: cspellDictModule.createSpellingDictionary,
|
|
36
34
|
createIgnoreWordsDictionary: cspellDictModule.createIgnoreWordsDictionary,
|
|
35
|
+
createSpellingDictionaryFromTrieFile: cspellDictModule.createSpellingDictionaryFromTrieFile,
|
|
37
36
|
};
|
|
38
|
-
const flagUseCSpellDictionary = 'use-cspell-dictionary';
|
|
39
|
-
(0, FeatureFlags_1.getSystemFeatureFlags)().register(flagUseCSpellDictionary, 'Use the CSpell Dictionary module.');
|
|
40
37
|
function getSpellDictInterface() {
|
|
41
|
-
|
|
42
|
-
return useModule ? SpellingDictionaryModule : SpellingDictionaryLibOld_1.SpellingDictionaryLibOld;
|
|
38
|
+
return SpellingDictionaryModule;
|
|
43
39
|
}
|
|
44
40
|
exports.getSpellDictInterface = getSpellDictInterface;
|
|
45
41
|
exports.createSpellingDictionary = getSpellDictInterface().createSpellingDictionary;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Sequence } from 'gensequence';
|
|
2
|
-
import { SpellingDictionary } from '
|
|
2
|
+
import { SpellingDictionary } from 'cspell-dictionary';
|
|
3
3
|
import * as TextRange from '../util/TextRange';
|
|
4
4
|
import { IncludeExcludeOptions, LineSegment, ValidationOptions, ValidationResult } from './ValidationTypes';
|
|
5
5
|
export declare const defaultMaxNumberOfProblems = 200;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-lib",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.12.0",
|
|
4
4
|
"description": "A library of useful functions used across various cspell tools.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -48,18 +48,18 @@
|
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://github.com/streetsidesoftware/cspell#readme",
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@cspell/cspell-bundled-dicts": "^6.
|
|
52
|
-
"@cspell/cspell-pipe": "^6.
|
|
53
|
-
"@cspell/cspell-types": "^6.
|
|
51
|
+
"@cspell/cspell-bundled-dicts": "^6.12.0",
|
|
52
|
+
"@cspell/cspell-pipe": "^6.12.0",
|
|
53
|
+
"@cspell/cspell-types": "^6.12.0",
|
|
54
54
|
"clear-module": "^4.1.2",
|
|
55
55
|
"comment-json": "^4.2.3",
|
|
56
56
|
"configstore": "^5.0.1",
|
|
57
57
|
"cosmiconfig": "^7.0.1",
|
|
58
|
-
"cspell-dictionary": "^6.
|
|
59
|
-
"cspell-glob": "^6.
|
|
60
|
-
"cspell-grammar": "^6.
|
|
61
|
-
"cspell-io": "^6.
|
|
62
|
-
"cspell-trie-lib": "^6.
|
|
58
|
+
"cspell-dictionary": "^6.12.0",
|
|
59
|
+
"cspell-glob": "^6.12.0",
|
|
60
|
+
"cspell-grammar": "^6.12.0",
|
|
61
|
+
"cspell-io": "^6.12.0",
|
|
62
|
+
"cspell-trie-lib": "^6.12.0",
|
|
63
63
|
"fast-equals": "^4.0.3",
|
|
64
64
|
"find-up": "^5.0.0",
|
|
65
65
|
"fs-extra": "^10.1.0",
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"rollup-plugin-dts": "^4.2.2",
|
|
95
95
|
"ts-jest": "^29.0.3"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "211105141a72268d45710661d2a9b15656ecf65e"
|
|
98
98
|
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestOptions, } from 'cspell-dictionary';
|
|
2
|
-
export { CompoundWordsMethod } from 'cspell-trie-lib';
|
|
3
|
-
export type { SuggestionCollector, SuggestionResult } from 'cspell-trie-lib';
|
|
4
|
-
//# sourceMappingURL=SpellingDictionary.d.ts.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompoundWordsMethod = void 0;
|
|
4
|
-
var cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
|
-
Object.defineProperty(exports, "CompoundWordsMethod", { enumerable: true, get: function () { return cspell_trie_lib_1.CompoundWordsMethod; } });
|
|
6
|
-
//# sourceMappingURL=SpellingDictionary.js.map
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { CompoundWordsMethod, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions } from './SpellingDictionary';
|
|
2
|
-
declare function identityString(w: string): string;
|
|
3
|
-
declare class SpellingDictionaryCollection implements SpellingDictionary {
|
|
4
|
-
readonly dictionaries: SpellingDictionary[];
|
|
5
|
-
readonly name: string;
|
|
6
|
-
readonly options: SpellingDictionaryOptions;
|
|
7
|
-
readonly mapWord: typeof identityString;
|
|
8
|
-
readonly type = "SpellingDictionaryCollection";
|
|
9
|
-
readonly source: string;
|
|
10
|
-
readonly isDictionaryCaseSensitive: boolean;
|
|
11
|
-
readonly containsNoSuggestWords: boolean;
|
|
12
|
-
constructor(dictionaries: SpellingDictionary[], name: string);
|
|
13
|
-
has(word: string, hasOptions?: HasOptions): boolean;
|
|
14
|
-
find(word: string, hasOptions?: HasOptions): FindResult | undefined;
|
|
15
|
-
isNoSuggestWord(word: string, options?: HasOptions): boolean;
|
|
16
|
-
isForbidden(word: string): boolean;
|
|
17
|
-
suggest(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean): SuggestionResult[];
|
|
18
|
-
suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[];
|
|
19
|
-
_suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[];
|
|
20
|
-
get size(): number;
|
|
21
|
-
genSuggestions(collector: SuggestionCollector, suggestOptions: SuggestOptions): void;
|
|
22
|
-
getErrors(): Error[];
|
|
23
|
-
private _isForbiddenInDict;
|
|
24
|
-
private _isNoSuggestWord;
|
|
25
|
-
}
|
|
26
|
-
export declare const SpellingDictionaryCollectionLegacy: typeof SpellingDictionaryCollection;
|
|
27
|
-
export declare function createCollection(dictionaries: SpellingDictionary[], name: string): SpellingDictionaryCollection;
|
|
28
|
-
declare function isWordInAnyDictionary(dicts: SpellingDictionary[], word: string, options: SearchOptions): SpellingDictionary | undefined;
|
|
29
|
-
declare function isWordForbiddenInAnyDictionary(dicts: SpellingDictionary[], word: string): SpellingDictionary | undefined;
|
|
30
|
-
export declare const __testing__: {
|
|
31
|
-
isWordInAnyDictionary: typeof isWordInAnyDictionary;
|
|
32
|
-
isWordForbiddenInAnyDictionary: typeof isWordForbiddenInAnyDictionary;
|
|
33
|
-
};
|
|
34
|
-
export {};
|
|
35
|
-
//# sourceMappingURL=SpellingDictionaryCollection.d.ts.map
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.__testing__ = exports.createCollection = exports.SpellingDictionaryCollectionLegacy = void 0;
|
|
4
|
-
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
|
-
const gensequence_1 = require("gensequence");
|
|
6
|
-
const Settings_1 = require("../../Settings");
|
|
7
|
-
const Memorizer_1 = require("../../util/Memorizer");
|
|
8
|
-
const util_1 = require("../../util/util");
|
|
9
|
-
const SpellingDictionary_1 = require("./SpellingDictionary");
|
|
10
|
-
const SpellingDictionaryFromTrie_1 = require("./SpellingDictionaryFromTrie");
|
|
11
|
-
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
12
|
-
function identityString(w) {
|
|
13
|
-
return w;
|
|
14
|
-
}
|
|
15
|
-
class SpellingDictionaryCollection {
|
|
16
|
-
constructor(dictionaries, name) {
|
|
17
|
-
this.dictionaries = dictionaries;
|
|
18
|
-
this.name = name;
|
|
19
|
-
this.options = { weightMap: undefined };
|
|
20
|
-
this.mapWord = identityString;
|
|
21
|
-
this.type = 'SpellingDictionaryCollection';
|
|
22
|
-
this._isForbiddenInDict = (0, Memorizer_1.memorizer)((word) => isWordForbiddenInAnyDictionary(this.dictionaries, word), SpellingDictionaryFromTrie_1.SpellingDictionaryFromTrie.cachedWordsLimit);
|
|
23
|
-
this._isNoSuggestWord = (0, Memorizer_1.memorizerKeyBy)((word, options) => {
|
|
24
|
-
if (!this.containsNoSuggestWords)
|
|
25
|
-
return false;
|
|
26
|
-
return !!isNoSuggestWordInAnyDictionary(this.dictionaries, word, options || {});
|
|
27
|
-
}, (word, options) => {
|
|
28
|
-
const opts = (0, SpellingDictionaryMethods_1.hasOptionToSearchOption)(options);
|
|
29
|
-
return [word, opts.useCompounds, opts.ignoreCase].join();
|
|
30
|
-
}, SpellingDictionaryFromTrie_1.SpellingDictionaryFromTrie.cachedWordsLimit);
|
|
31
|
-
this.dictionaries = this.dictionaries.sort((a, b) => b.size - a.size);
|
|
32
|
-
this.source = dictionaries.map((d) => d.name).join(', ');
|
|
33
|
-
this.isDictionaryCaseSensitive = this.dictionaries.reduce((a, b) => a || b.isDictionaryCaseSensitive, false);
|
|
34
|
-
this.containsNoSuggestWords = this.dictionaries.reduce((a, b) => a || b.containsNoSuggestWords, false);
|
|
35
|
-
}
|
|
36
|
-
has(word, hasOptions) {
|
|
37
|
-
const options = (0, SpellingDictionaryMethods_1.hasOptionToSearchOption)(hasOptions);
|
|
38
|
-
return !!isWordInAnyDictionary(this.dictionaries, word, options) && !this.isForbidden(word);
|
|
39
|
-
}
|
|
40
|
-
find(word, hasOptions) {
|
|
41
|
-
const options = (0, SpellingDictionaryMethods_1.hasOptionToSearchOption)(hasOptions);
|
|
42
|
-
const { found = false, forbidden = false, noSuggest = false, } = findInAnyDictionary(this.dictionaries, word, options) || {};
|
|
43
|
-
return { found, forbidden, noSuggest };
|
|
44
|
-
}
|
|
45
|
-
isNoSuggestWord(word, options) {
|
|
46
|
-
return this._isNoSuggestWord(word, options);
|
|
47
|
-
}
|
|
48
|
-
isForbidden(word) {
|
|
49
|
-
return !!this._isForbiddenInDict(word) && !this.isNoSuggestWord(word);
|
|
50
|
-
}
|
|
51
|
-
suggest(...args) {
|
|
52
|
-
const [word] = args;
|
|
53
|
-
const suggestOptions = (0, SpellingDictionaryMethods_1.suggestArgsToSuggestOptions)(args);
|
|
54
|
-
return this._suggest(word, suggestOptions);
|
|
55
|
-
}
|
|
56
|
-
_suggest(word, suggestOptions) {
|
|
57
|
-
const { numSuggestions = (0, Settings_1.getDefaultSettings)(false).numSuggestions || SpellingDictionaryMethods_1.defaultNumSuggestions, numChanges, ignoreCase, includeTies, timeout, } = suggestOptions;
|
|
58
|
-
const prefixNoCase = cspell_trie_lib_1.CASE_INSENSITIVE_PREFIX;
|
|
59
|
-
const filter = (word, _cost) => {
|
|
60
|
-
return ((ignoreCase || word[0] !== prefixNoCase) &&
|
|
61
|
-
!this.isForbidden(word) &&
|
|
62
|
-
!this.isNoSuggestWord(word, suggestOptions));
|
|
63
|
-
};
|
|
64
|
-
const collector = (0, SpellingDictionaryMethods_1.suggestionCollector)(word, (0, util_1.clean)({
|
|
65
|
-
numSuggestions,
|
|
66
|
-
filter,
|
|
67
|
-
changeLimit: numChanges,
|
|
68
|
-
includeTies,
|
|
69
|
-
ignoreCase,
|
|
70
|
-
timeout,
|
|
71
|
-
}));
|
|
72
|
-
this.genSuggestions(collector, suggestOptions);
|
|
73
|
-
return collector.suggestions.map((r) => ({ ...r, word: r.word }));
|
|
74
|
-
}
|
|
75
|
-
get size() {
|
|
76
|
-
return this.dictionaries.reduce((a, b) => a + b.size, 0);
|
|
77
|
-
}
|
|
78
|
-
genSuggestions(collector, suggestOptions) {
|
|
79
|
-
const _suggestOptions = { ...suggestOptions };
|
|
80
|
-
const { compoundMethod = SpellingDictionary_1.CompoundWordsMethod.SEPARATE_WORDS } = suggestOptions;
|
|
81
|
-
_suggestOptions.compoundMethod = this.options.useCompounds ? SpellingDictionary_1.CompoundWordsMethod.JOIN_WORDS : compoundMethod;
|
|
82
|
-
this.dictionaries.forEach((dict) => dict.genSuggestions(collector, _suggestOptions));
|
|
83
|
-
}
|
|
84
|
-
getErrors() {
|
|
85
|
-
return this.dictionaries.reduce((errors, dict) => errors.concat(dict.getErrors?.() || []), []);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.SpellingDictionaryCollectionLegacy = SpellingDictionaryCollection;
|
|
89
|
-
function createCollection(dictionaries, name) {
|
|
90
|
-
return new SpellingDictionaryCollection(dictionaries, name);
|
|
91
|
-
}
|
|
92
|
-
exports.createCollection = createCollection;
|
|
93
|
-
function isWordInAnyDictionary(dicts, word, options) {
|
|
94
|
-
return (0, gensequence_1.genSequence)(dicts).first((dict) => dict.has(word, options));
|
|
95
|
-
}
|
|
96
|
-
function findInAnyDictionary(dicts, word, options) {
|
|
97
|
-
const found = dicts.map((dict) => dict.find(word, options)).filter(util_1.isDefined);
|
|
98
|
-
if (!found.length)
|
|
99
|
-
return undefined;
|
|
100
|
-
return found.reduce((a, b) => ({
|
|
101
|
-
found: a.forbidden ? a.found : b.forbidden ? b.found : a.found || b.found,
|
|
102
|
-
forbidden: a.forbidden || b.forbidden,
|
|
103
|
-
noSuggest: a.noSuggest || b.noSuggest,
|
|
104
|
-
}));
|
|
105
|
-
}
|
|
106
|
-
function isNoSuggestWordInAnyDictionary(dicts, word, options) {
|
|
107
|
-
return (0, gensequence_1.genSequence)(dicts).first((dict) => dict.isNoSuggestWord(word, options));
|
|
108
|
-
}
|
|
109
|
-
function isWordForbiddenInAnyDictionary(dicts, word) {
|
|
110
|
-
return (0, gensequence_1.genSequence)(dicts).first((dict) => dict.isForbidden(word));
|
|
111
|
-
}
|
|
112
|
-
exports.__testing__ = {
|
|
113
|
-
isWordInAnyDictionary,
|
|
114
|
-
isWordForbiddenInAnyDictionary,
|
|
115
|
-
};
|
|
116
|
-
//# sourceMappingURL=SpellingDictionaryCollection.js.map
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { SuggestionCollector, SuggestionResult } from 'cspell-trie-lib';
|
|
2
|
-
import { CompoundWordsMethod, Trie } from 'cspell-trie-lib';
|
|
3
|
-
import { FindResult, HasOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestOptions } from './SpellingDictionary';
|
|
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 type = "SpellingDictionaryFromTrie";
|
|
15
|
-
readonly isDictionaryCaseSensitive: boolean;
|
|
16
|
-
readonly containsNoSuggestWords: boolean;
|
|
17
|
-
readonly ignoreCharactersRegExp: RegExp | undefined;
|
|
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): boolean;
|
|
29
|
-
suggest(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean): SuggestionResult[];
|
|
30
|
-
suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[];
|
|
31
|
-
private _suggest;
|
|
32
|
-
genSuggestions(collector: SuggestionCollector, suggestOptions: SuggestOptions): void;
|
|
33
|
-
getErrors(): Error[];
|
|
34
|
-
}
|
|
35
|
-
export declare function createSpellingDictionaryTrie(data: Iterable<string>, name: string, source: string, options: SpellingDictionaryOptions): SpellingDictionary;
|
|
36
|
-
//# sourceMappingURL=SpellingDictionaryFromTrie.d.ts.map
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSpellingDictionaryTrie = exports.SpellingDictionaryFromTrie = void 0;
|
|
4
|
-
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
|
-
const Settings_1 = require("../../Settings");
|
|
6
|
-
const Memorizer_1 = require("../../util/Memorizer");
|
|
7
|
-
const repMap_1 = require("../../util/repMap");
|
|
8
|
-
const util_1 = require("../../util/util");
|
|
9
|
-
const charset_1 = require("./charset");
|
|
10
|
-
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
11
|
-
class SpellingDictionaryFromTrie {
|
|
12
|
-
constructor(trie, name, options, source = 'from trie', size) {
|
|
13
|
-
this.trie = trie;
|
|
14
|
-
this.name = name;
|
|
15
|
-
this.options = options;
|
|
16
|
-
this.source = source;
|
|
17
|
-
this._size = 0;
|
|
18
|
-
this.knownWords = new Set();
|
|
19
|
-
this.unknownWords = new Set();
|
|
20
|
-
this.type = 'SpellingDictionaryFromTrie';
|
|
21
|
-
this._find = (0, Memorizer_1.memorizer)((word, useCompounds, ignoreCase) => this.findAnyForm(word, useCompounds, ignoreCase), SpellingDictionaryFromTrie.cachedWordsLimit);
|
|
22
|
-
this.mapWord = (0, repMap_1.createMapper)(options.repMap || []);
|
|
23
|
-
this.isDictionaryCaseSensitive = options.caseSensitive ?? !trie.isLegacy;
|
|
24
|
-
this.containsNoSuggestWords = options.noSuggest || false;
|
|
25
|
-
this._size = size || 0;
|
|
26
|
-
this.weightMap = options.weightMap || (0, SpellingDictionaryMethods_1.createWeightMapFromDictionaryInformation)(options.dictionaryInformation);
|
|
27
|
-
this.ignoreCharactersRegExp = (0, charset_1.charsetToRegExp)(this.options.dictionaryInformation?.ignore);
|
|
28
|
-
}
|
|
29
|
-
get size() {
|
|
30
|
-
if (!this._size) {
|
|
31
|
-
// walk the trie and get the approximate size.
|
|
32
|
-
const i = this.trie.iterate();
|
|
33
|
-
let deeper = true;
|
|
34
|
-
let size = 0;
|
|
35
|
-
for (let r = i.next(); !r.done; r = i.next(deeper)) {
|
|
36
|
-
// count all nodes even though they are not words.
|
|
37
|
-
// because we are not going to all the leaves, this should give a good enough approximation.
|
|
38
|
-
size += 1;
|
|
39
|
-
deeper = r.value.text.length < 5;
|
|
40
|
-
}
|
|
41
|
-
this._size = size;
|
|
42
|
-
}
|
|
43
|
-
return this._size;
|
|
44
|
-
}
|
|
45
|
-
has(word, hasOptions) {
|
|
46
|
-
const { useCompounds, ignoreCase } = this.resolveOptions(hasOptions);
|
|
47
|
-
const r = this._find(word, useCompounds, ignoreCase);
|
|
48
|
-
return !!r && !r.forbidden && !!r.found;
|
|
49
|
-
}
|
|
50
|
-
find(word, hasOptions) {
|
|
51
|
-
const { useCompounds, ignoreCase } = this.resolveOptions(hasOptions);
|
|
52
|
-
const r = this._find(word, useCompounds, ignoreCase);
|
|
53
|
-
const { forbidden = this.isForbidden(word) } = r || {};
|
|
54
|
-
if (!r && !forbidden)
|
|
55
|
-
return undefined;
|
|
56
|
-
const { found = forbidden ? word : false } = r || {};
|
|
57
|
-
const noSuggest = found !== false && this.containsNoSuggestWords;
|
|
58
|
-
return { found, forbidden, noSuggest };
|
|
59
|
-
}
|
|
60
|
-
resolveOptions(hasOptions) {
|
|
61
|
-
const { useCompounds = this.options.useCompounds, ignoreCase = true } = (0, SpellingDictionaryMethods_1.hasOptionToSearchOption)(hasOptions);
|
|
62
|
-
return { useCompounds, ignoreCase };
|
|
63
|
-
}
|
|
64
|
-
findAnyForm(word, useCompounds, ignoreCase) {
|
|
65
|
-
const outerForms = new Set([word]);
|
|
66
|
-
if (this.ignoreCharactersRegExp) {
|
|
67
|
-
outerForms.add(word.replace(this.ignoreCharactersRegExp, ''));
|
|
68
|
-
outerForms.add(word.normalize('NFD').replace(this.ignoreCharactersRegExp, ''));
|
|
69
|
-
outerForms.add(word.normalize('NFC').replace(this.ignoreCharactersRegExp, ''));
|
|
70
|
-
}
|
|
71
|
-
for (const form of outerForms) {
|
|
72
|
-
const r = this._findAnyForm(form, useCompounds, ignoreCase);
|
|
73
|
-
if (r)
|
|
74
|
-
return r;
|
|
75
|
-
}
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
_findAnyForm(word, useCompounds, ignoreCase) {
|
|
79
|
-
const mWord = this.mapWord(word.normalize('NFC'));
|
|
80
|
-
const opts = { caseSensitive: !ignoreCase };
|
|
81
|
-
const findResult = this.trie.findWord(mWord, opts);
|
|
82
|
-
if (findResult.found !== false) {
|
|
83
|
-
return findResult;
|
|
84
|
-
}
|
|
85
|
-
const forms = (0, SpellingDictionaryMethods_1.wordSearchForms)(mWord, this.isDictionaryCaseSensitive, ignoreCase);
|
|
86
|
-
for (const w of forms) {
|
|
87
|
-
const findResult = this.trie.findWord(w, opts);
|
|
88
|
-
if (findResult.found !== false) {
|
|
89
|
-
return findResult;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (useCompounds) {
|
|
93
|
-
opts.useLegacyWordCompounds = useCompounds;
|
|
94
|
-
for (const w of forms) {
|
|
95
|
-
const findResult = this.trie.findWord(w, opts);
|
|
96
|
-
if (findResult.found !== false) {
|
|
97
|
-
return findResult;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return undefined;
|
|
102
|
-
}
|
|
103
|
-
isNoSuggestWord(word, options) {
|
|
104
|
-
return this.containsNoSuggestWords ? this.has(word, options) : false;
|
|
105
|
-
}
|
|
106
|
-
isForbidden(word) {
|
|
107
|
-
return this.trie.isForbiddenWord(word);
|
|
108
|
-
}
|
|
109
|
-
suggest(...args) {
|
|
110
|
-
const [word] = args;
|
|
111
|
-
const suggestOptions = (0, SpellingDictionaryMethods_1.suggestArgsToSuggestOptions)(args);
|
|
112
|
-
return this._suggest(word, suggestOptions);
|
|
113
|
-
}
|
|
114
|
-
_suggest(word, suggestOptions) {
|
|
115
|
-
const { numSuggestions = (0, Settings_1.getDefaultSettings)(false).numSuggestions || SpellingDictionaryMethods_1.defaultNumSuggestions, numChanges, includeTies, ignoreCase, timeout, } = suggestOptions;
|
|
116
|
-
function filter(_word) {
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
const collector = (0, cspell_trie_lib_1.suggestionCollector)(word, (0, util_1.clean)({
|
|
120
|
-
numSuggestions,
|
|
121
|
-
filter,
|
|
122
|
-
changeLimit: numChanges,
|
|
123
|
-
includeTies,
|
|
124
|
-
ignoreCase,
|
|
125
|
-
timeout,
|
|
126
|
-
weightMap: this.weightMap,
|
|
127
|
-
}));
|
|
128
|
-
this.genSuggestions(collector, suggestOptions);
|
|
129
|
-
return collector.suggestions.map((r) => ({ ...r, word: r.word }));
|
|
130
|
-
}
|
|
131
|
-
genSuggestions(collector, suggestOptions) {
|
|
132
|
-
if (this.options.noSuggest)
|
|
133
|
-
return;
|
|
134
|
-
const _compoundMethod = suggestOptions.compoundMethod ??
|
|
135
|
-
(this.options.useCompounds ? cspell_trie_lib_1.CompoundWordsMethod.JOIN_WORDS : cspell_trie_lib_1.CompoundWordsMethod.NONE);
|
|
136
|
-
(0, SpellingDictionaryMethods_1.wordSuggestFormsArray)(collector.word).forEach((w) => this.trie.genSuggestions((0, SpellingDictionaryMethods_1.impersonateCollector)(collector, w), _compoundMethod));
|
|
137
|
-
}
|
|
138
|
-
getErrors() {
|
|
139
|
-
return [];
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
exports.SpellingDictionaryFromTrie = SpellingDictionaryFromTrie;
|
|
143
|
-
SpellingDictionaryFromTrie.cachedWordsLimit = 50000;
|
|
144
|
-
function createSpellingDictionaryTrie(data, name, source, options) {
|
|
145
|
-
const trieNode = (0, cspell_trie_lib_1.importTrie)(data);
|
|
146
|
-
const trie = new cspell_trie_lib_1.Trie(trieNode);
|
|
147
|
-
return new SpellingDictionaryFromTrie(trie, name, options, source);
|
|
148
|
-
}
|
|
149
|
-
exports.createSpellingDictionaryTrie = createSpellingDictionaryTrie;
|
|
150
|
-
//# sourceMappingURL=SpellingDictionaryFromTrie.js.map
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { DictionaryInformation } from '@cspell/cspell-types';
|
|
2
|
-
import { CompoundWordsMethod, SuggestionResult, WeightMap } from 'cspell-trie-lib';
|
|
3
|
-
import { HasOptions, SearchOptions, SpellingDictionary, SuggestOptions } from './SpellingDictionary';
|
|
4
|
-
export { impersonateCollector, suggestionCollector } from 'cspell-trie-lib';
|
|
5
|
-
export declare type FilterSuggestionsPredicate = (word: SuggestionResult) => boolean;
|
|
6
|
-
export declare type SuggestArgs = Parameters<SpellingDictionary['suggest']> | Parameters<(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean) => SuggestionResult[]>;
|
|
7
|
-
export declare const defaultNumSuggestions = 10;
|
|
8
|
-
declare function wordSearchFormsArray(word: string, isDictionaryCaseSensitive: boolean, ignoreCase: boolean): string[];
|
|
9
|
-
export declare function wordSearchForms(word: string, isDictionaryCaseSensitive: boolean, ignoreCase: boolean): Set<string>;
|
|
10
|
-
export declare function wordSuggestFormsArray(word: string): string[];
|
|
11
|
-
export declare function wordSuggestForms(word: string): Set<string>;
|
|
12
|
-
interface DictionaryWordForm {
|
|
13
|
-
w: string;
|
|
14
|
-
p: string;
|
|
15
|
-
}
|
|
16
|
-
declare function wordDictionaryForms(word: string, prefixNoCase: string): IterableIterator<DictionaryWordForm>;
|
|
17
|
-
export declare function wordDictionaryFormsCollector(prefixNoCase: string): (word: string) => Iterable<string>;
|
|
18
|
-
export declare function hasOptionToSearchOption(opt: HasOptions | undefined): SearchOptions;
|
|
19
|
-
export declare function suggestArgsToSuggestOptions(args: SuggestArgs): SuggestOptions;
|
|
20
|
-
export declare function createWeightMapFromDictionaryInformation(di: undefined): undefined;
|
|
21
|
-
export declare function createWeightMapFromDictionaryInformation(di: DictionaryInformation): WeightMap;
|
|
22
|
-
export declare function createWeightMapFromDictionaryInformation(di: DictionaryInformation | undefined): WeightMap | undefined;
|
|
23
|
-
export declare const __testMethods__: {
|
|
24
|
-
wordSearchForms: typeof wordSearchForms;
|
|
25
|
-
wordSearchFormsArray: typeof wordSearchFormsArray;
|
|
26
|
-
wordDictionaryForms: typeof wordDictionaryForms;
|
|
27
|
-
wordDictionaryFormsCollector: typeof wordDictionaryFormsCollector;
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=SpellingDictionaryMethods.d.ts.map
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.__testMethods__ = exports.createWeightMapFromDictionaryInformation = exports.suggestArgsToSuggestOptions = exports.hasOptionToSearchOption = exports.wordDictionaryFormsCollector = exports.wordSuggestForms = exports.wordSuggestFormsArray = exports.wordSearchForms = exports.defaultNumSuggestions = exports.suggestionCollector = exports.impersonateCollector = void 0;
|
|
4
|
-
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
|
-
const trie_util_1 = require("cspell-trie-lib/dist/lib/trie-util");
|
|
6
|
-
const gensequence_1 = require("gensequence");
|
|
7
|
-
const text_1 = require("../../util/text");
|
|
8
|
-
var cspell_trie_lib_2 = require("cspell-trie-lib");
|
|
9
|
-
Object.defineProperty(exports, "impersonateCollector", { enumerable: true, get: function () { return cspell_trie_lib_2.impersonateCollector; } });
|
|
10
|
-
Object.defineProperty(exports, "suggestionCollector", { enumerable: true, get: function () { return cspell_trie_lib_2.suggestionCollector; } });
|
|
11
|
-
exports.defaultNumSuggestions = 10;
|
|
12
|
-
function wordSearchFormsArray(word, isDictionaryCaseSensitive, ignoreCase) {
|
|
13
|
-
return [...wordSearchForms(word, isDictionaryCaseSensitive, ignoreCase)];
|
|
14
|
-
}
|
|
15
|
-
function wordSearchForms(word, isDictionaryCaseSensitive, ignoreCase) {
|
|
16
|
-
const forms = new Set();
|
|
17
|
-
word = word.normalize('NFC');
|
|
18
|
-
const wordLc = word.toLowerCase();
|
|
19
|
-
if (ignoreCase) {
|
|
20
|
-
if (isDictionaryCaseSensitive) {
|
|
21
|
-
forms.add(wordLc);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
forms.add(wordLc);
|
|
25
|
-
// Legacy remove any unbound accents
|
|
26
|
-
forms.add(wordLc.replace(/\p{M}/gu, ''));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
if (isDictionaryCaseSensitive) {
|
|
31
|
-
forms.add(word);
|
|
32
|
-
forms.add(wordLc);
|
|
33
|
-
// HOUSE -> House, house
|
|
34
|
-
if ((0, text_1.isUpperCase)(word)) {
|
|
35
|
-
forms.add((0, text_1.ucFirst)(wordLc));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
forms.add(wordLc);
|
|
40
|
-
// Legacy remove any unbound accents
|
|
41
|
-
forms.add(wordLc.replace(/\p{M}/gu, ''));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return forms;
|
|
45
|
-
}
|
|
46
|
-
exports.wordSearchForms = wordSearchForms;
|
|
47
|
-
function wordSuggestFormsArray(word) {
|
|
48
|
-
return [...wordSuggestForms(word)];
|
|
49
|
-
}
|
|
50
|
-
exports.wordSuggestFormsArray = wordSuggestFormsArray;
|
|
51
|
-
function wordSuggestForms(word) {
|
|
52
|
-
word = word.normalize('NFC');
|
|
53
|
-
const forms = new Set([word]);
|
|
54
|
-
const wordLc = word.toLowerCase();
|
|
55
|
-
forms.add(wordLc);
|
|
56
|
-
return forms;
|
|
57
|
-
}
|
|
58
|
-
exports.wordSuggestForms = wordSuggestForms;
|
|
59
|
-
function* wordDictionaryForms(word, prefixNoCase) {
|
|
60
|
-
word = word.normalize('NFC');
|
|
61
|
-
const wordLc = word.toLowerCase();
|
|
62
|
-
const wordNa = (0, text_1.removeAccents)(word);
|
|
63
|
-
const wordLcNa = (0, text_1.removeAccents)(wordLc);
|
|
64
|
-
function wf(w, p = '') {
|
|
65
|
-
return { w, p };
|
|
66
|
-
}
|
|
67
|
-
const prefix = prefixNoCase;
|
|
68
|
-
yield wf(word);
|
|
69
|
-
yield wf(wordNa, prefix);
|
|
70
|
-
yield wf(wordLc, prefix);
|
|
71
|
-
yield wf(wordLcNa, prefix);
|
|
72
|
-
}
|
|
73
|
-
function wordDictionaryFormsCollector(prefixNoCase) {
|
|
74
|
-
const knownWords = new Set();
|
|
75
|
-
return (word) => {
|
|
76
|
-
return (0, gensequence_1.genSequence)(wordDictionaryForms(word, prefixNoCase))
|
|
77
|
-
.filter((w) => !knownWords.has(w.w))
|
|
78
|
-
.map((w) => w.p + w.w)
|
|
79
|
-
.filter((w) => !knownWords.has(w))
|
|
80
|
-
.map((w) => (knownWords.add(w), w));
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
exports.wordDictionaryFormsCollector = wordDictionaryFormsCollector;
|
|
84
|
-
const DEFAULT_HAS_OPTIONS = Object.freeze({});
|
|
85
|
-
function hasOptionToSearchOption(opt) {
|
|
86
|
-
return !opt ? DEFAULT_HAS_OPTIONS : opt;
|
|
87
|
-
}
|
|
88
|
-
exports.hasOptionToSearchOption = hasOptionToSearchOption;
|
|
89
|
-
function suggestArgsToSuggestOptions(args) {
|
|
90
|
-
const [_word, options, compoundMethod, numChanges, ignoreCase] = args;
|
|
91
|
-
const suggestOptions = typeof options === 'object'
|
|
92
|
-
? options
|
|
93
|
-
: (0, trie_util_1.clean)({
|
|
94
|
-
numSuggestions: options,
|
|
95
|
-
compoundMethod,
|
|
96
|
-
numChanges,
|
|
97
|
-
ignoreCase,
|
|
98
|
-
includeTies: undefined,
|
|
99
|
-
timeout: undefined,
|
|
100
|
-
});
|
|
101
|
-
return suggestOptions;
|
|
102
|
-
}
|
|
103
|
-
exports.suggestArgsToSuggestOptions = suggestArgsToSuggestOptions;
|
|
104
|
-
function createWeightMapFromDictionaryInformation(di) {
|
|
105
|
-
return di ? (0, cspell_trie_lib_1.mapDictionaryInformationToWeightMap)(di) : undefined;
|
|
106
|
-
}
|
|
107
|
-
exports.createWeightMapFromDictionaryInformation = createWeightMapFromDictionaryInformation;
|
|
108
|
-
exports.__testMethods__ = {
|
|
109
|
-
wordSearchForms,
|
|
110
|
-
wordSearchFormsArray,
|
|
111
|
-
wordDictionaryForms,
|
|
112
|
-
wordDictionaryFormsCollector,
|
|
113
|
-
};
|
|
114
|
-
//# sourceMappingURL=SpellingDictionaryMethods.js.map
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.charsetToRegExp = void 0;
|
|
4
|
-
function charsetToRegExp(charset) {
|
|
5
|
-
if (!charset)
|
|
6
|
-
return undefined;
|
|
7
|
-
try {
|
|
8
|
-
const reg = `[${charset.replace(/[\][\\]/g, '\\$&')}]`;
|
|
9
|
-
return new RegExp(reg, 'g');
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.charsetToRegExp = charsetToRegExp;
|
|
16
|
-
//# sourceMappingURL=charset.js.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { IterableLike } from '../../util/IterableLike';
|
|
2
|
-
import { SpellingDictionary, SpellingDictionaryOptions } from './SpellingDictionary';
|
|
3
|
-
import { SpellingDictionaryLoadError } from '../SpellingDictionaryError';
|
|
4
|
-
export declare function createSpellingDictionary(wordList: readonly string[] | IterableLike<string>, name: string, source: string, options: SpellingDictionaryOptions | undefined): SpellingDictionary;
|
|
5
|
-
export declare function createForbiddenWordsDictionary(wordList: readonly string[], name: string, source: string, options: SpellingDictionaryOptions | undefined): SpellingDictionary;
|
|
6
|
-
export declare function createFailedToLoadDictionary(error: SpellingDictionaryLoadError): SpellingDictionary;
|
|
7
|
-
export declare function createIgnoreWordsDictionary(wordList: readonly string[], name: string, source: string): SpellingDictionary;
|
|
8
|
-
//# sourceMappingURL=createSpellingDictionary.d.ts.map
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createIgnoreWordsDictionary = exports.createFailedToLoadDictionary = exports.createForbiddenWordsDictionary = exports.createSpellingDictionary = void 0;
|
|
4
|
-
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
|
-
const fast_equals_1 = require("fast-equals");
|
|
6
|
-
const gensequence_1 = require("gensequence");
|
|
7
|
-
const simpleCache_1 = require("../../util/simpleCache");
|
|
8
|
-
const SpellingDictionaryFromTrie_1 = require("./SpellingDictionaryFromTrie");
|
|
9
|
-
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
10
|
-
const defaultOptions = Object.freeze({
|
|
11
|
-
weightMap: undefined,
|
|
12
|
-
});
|
|
13
|
-
const cachedDictionaries = new simpleCache_1.AutoWeakCache(_createSpellingDictionary, 64);
|
|
14
|
-
const maxSetSize = 3;
|
|
15
|
-
const cachedParamsByWordList = new simpleCache_1.SimpleCache(64);
|
|
16
|
-
function createSpellingDictionary(wordList, name, source, options) {
|
|
17
|
-
const params = [wordList, name, source, options];
|
|
18
|
-
if (!Array.isArray(wordList)) {
|
|
19
|
-
return _createSpellingDictionary(params);
|
|
20
|
-
}
|
|
21
|
-
const cached = cachedParamsByWordList.get(name) || new Set();
|
|
22
|
-
for (const cachedParams of cached) {
|
|
23
|
-
if ((0, fast_equals_1.deepEqual)(params, cachedParams)) {
|
|
24
|
-
return cachedDictionaries.get(cachedParams);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (cached.size > maxSetSize)
|
|
28
|
-
cached.clear();
|
|
29
|
-
cached.add(params);
|
|
30
|
-
cachedParamsByWordList.set(name, cached);
|
|
31
|
-
return cachedDictionaries.get(params);
|
|
32
|
-
}
|
|
33
|
-
exports.createSpellingDictionary = createSpellingDictionary;
|
|
34
|
-
function _createSpellingDictionary(params) {
|
|
35
|
-
const [wordList, name, source, options] = params;
|
|
36
|
-
// console.log(`createSpellingDictionary ${name} ${source}`);
|
|
37
|
-
const parseOptions = { stripCaseAndAccents: options?.supportNonStrictSearches ?? true };
|
|
38
|
-
const words = (0, cspell_trie_lib_1.parseDictionaryLines)(wordList, parseOptions);
|
|
39
|
-
const trie = (0, cspell_trie_lib_1.buildTrieFast)(words);
|
|
40
|
-
const opts = { ...(options || defaultOptions) };
|
|
41
|
-
if (opts.weightMap === undefined && opts.dictionaryInformation) {
|
|
42
|
-
opts.weightMap = (0, SpellingDictionaryMethods_1.createWeightMapFromDictionaryInformation)(opts.dictionaryInformation);
|
|
43
|
-
}
|
|
44
|
-
return new SpellingDictionaryFromTrie_1.SpellingDictionaryFromTrie(trie, name, opts, source);
|
|
45
|
-
}
|
|
46
|
-
function createForbiddenWordsDictionary(wordList, name, source, options) {
|
|
47
|
-
// console.log(`createForbiddenWordsDictionary ${name} ${source}`);
|
|
48
|
-
const words = (0, cspell_trie_lib_1.parseDictionaryLines)(wordList.concat(wordList.map((a) => a.toLowerCase())), {
|
|
49
|
-
stripCaseAndAccents: !options?.noSuggest,
|
|
50
|
-
});
|
|
51
|
-
const forbidWords = gensequence_1.operators.map((w) => '!' + w)(words);
|
|
52
|
-
const trie = (0, cspell_trie_lib_1.buildTrieFast)(forbidWords);
|
|
53
|
-
return new SpellingDictionaryFromTrie_1.SpellingDictionaryFromTrie(trie, name, options || defaultOptions, source);
|
|
54
|
-
}
|
|
55
|
-
exports.createForbiddenWordsDictionary = createForbiddenWordsDictionary;
|
|
56
|
-
function createFailedToLoadDictionary(error) {
|
|
57
|
-
const { options, uri: source } = error;
|
|
58
|
-
const errors = [error];
|
|
59
|
-
return {
|
|
60
|
-
name: options.name,
|
|
61
|
-
source,
|
|
62
|
-
type: 'error',
|
|
63
|
-
containsNoSuggestWords: false,
|
|
64
|
-
has: () => false,
|
|
65
|
-
find: () => undefined,
|
|
66
|
-
isNoSuggestWord: () => false,
|
|
67
|
-
isForbidden: () => false,
|
|
68
|
-
suggest: () => [],
|
|
69
|
-
mapWord: (a) => a,
|
|
70
|
-
genSuggestions: () => {
|
|
71
|
-
return;
|
|
72
|
-
},
|
|
73
|
-
size: 0,
|
|
74
|
-
options,
|
|
75
|
-
isDictionaryCaseSensitive: false,
|
|
76
|
-
getErrors: () => errors,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
exports.createFailedToLoadDictionary = createFailedToLoadDictionary;
|
|
80
|
-
function createIgnoreWordsDictionary(wordList, name, source) {
|
|
81
|
-
// console.log('createIgnoreWordsDictionary %o', wordList);
|
|
82
|
-
return createSpellingDictionary(wordList, name, source, {
|
|
83
|
-
caseSensitive: true,
|
|
84
|
-
noSuggest: true,
|
|
85
|
-
weightMap: undefined,
|
|
86
|
-
supportNonStrictSearches: true,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
exports.createIgnoreWordsDictionary = createIgnoreWordsDictionary;
|
|
90
|
-
//# sourceMappingURL=createSpellingDictionary.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './SpellingDictionary';
|
|
2
|
-
import { createCollection } from './SpellingDictionaryCollection';
|
|
3
|
-
import { createFailedToLoadDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createSpellingDictionary } from './createSpellingDictionary';
|
|
4
|
-
export declare const SpellingDictionaryLibOld: {
|
|
5
|
-
readonly createCollection: typeof createCollection;
|
|
6
|
-
readonly createFailedToLoadDictionary: typeof createFailedToLoadDictionary;
|
|
7
|
-
readonly createForbiddenWordsDictionary: typeof createForbiddenWordsDictionary;
|
|
8
|
-
readonly createIgnoreWordsDictionary: typeof createIgnoreWordsDictionary;
|
|
9
|
-
readonly createSpellingDictionary: typeof createSpellingDictionary;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,28 +0,0 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.SpellingDictionaryLibOld = void 0;
|
|
18
|
-
__exportStar(require("./SpellingDictionary"), exports);
|
|
19
|
-
const SpellingDictionaryCollection_1 = require("./SpellingDictionaryCollection");
|
|
20
|
-
const createSpellingDictionary_1 = require("./createSpellingDictionary");
|
|
21
|
-
exports.SpellingDictionaryLibOld = {
|
|
22
|
-
createCollection: SpellingDictionaryCollection_1.createCollection,
|
|
23
|
-
createFailedToLoadDictionary: createSpellingDictionary_1.createFailedToLoadDictionary,
|
|
24
|
-
createForbiddenWordsDictionary: createSpellingDictionary_1.createForbiddenWordsDictionary,
|
|
25
|
-
createIgnoreWordsDictionary: createSpellingDictionary_1.createIgnoreWordsDictionary,
|
|
26
|
-
createSpellingDictionary: createSpellingDictionary_1.createSpellingDictionary,
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=index.js.map
|