cspell-dictionary 6.10.0 → 6.11.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/CachingDictionary.d.ts +30 -0
- package/dist/SpellingDictionary/CachingDictionary.js +50 -0
- package/dist/SpellingDictionary/ForbiddenWordsDictionary.d.ts +11 -0
- package/dist/SpellingDictionary/ForbiddenWordsDictionary.js +107 -0
- package/dist/SpellingDictionary/IgnoreWordsDictionary.d.ts +11 -0
- package/dist/SpellingDictionary/IgnoreWordsDictionary.js +120 -0
- package/dist/SpellingDictionary/SpellingDictionary.d.ts +16 -2
- package/dist/SpellingDictionary/SpellingDictionaryCollection.d.ts +4 -22
- package/dist/SpellingDictionary/SpellingDictionaryCollection.js +7 -4
- package/dist/SpellingDictionary/SpellingDictionaryFromTrie.d.ts +15 -2
- package/dist/SpellingDictionary/SpellingDictionaryFromTrie.js +72 -20
- package/dist/SpellingDictionary/SpellingDictionaryMethods.d.ts +6 -8
- package/dist/SpellingDictionary/SpellingDictionaryMethods.js +30 -32
- package/dist/SpellingDictionary/createSpellingDictionary.d.ts +12 -5
- package/dist/SpellingDictionary/createSpellingDictionary.js +13 -28
- package/dist/SpellingDictionary/defaults.d.ts +2 -0
- package/dist/SpellingDictionary/defaults.js +5 -0
- package/dist/SpellingDictionary/index.d.ts +6 -2
- package/dist/SpellingDictionary/index.js +9 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -1
- package/dist/util/AutoCache.d.ts +25 -0
- package/dist/util/AutoCache.js +74 -0
- package/dist/util/repMap.d.ts +9 -2
- package/dist/util/repMap.js +38 -11
- package/dist/util/text.d.ts +1 -0
- package/dist/util/text.js +5 -1
- package/package.json +10 -5
- package/dist/SpellingDictionary/charset.d.ts +0 -3
- package/dist/SpellingDictionary/charset.js +0 -16
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CacheStats } from '../util/AutoCache';
|
|
2
|
+
import { SearchOptions, SpellingDictionary } from './SpellingDictionary';
|
|
3
|
+
import { SpellingDictionaryCollection } from './SpellingDictionaryCollection';
|
|
4
|
+
interface CallStats {
|
|
5
|
+
name: string;
|
|
6
|
+
id: number;
|
|
7
|
+
has: CacheStats;
|
|
8
|
+
isNoSuggestWord: CacheStats;
|
|
9
|
+
isForbidden: CacheStats;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Caching Dictionary remembers method calls to increase performance.
|
|
13
|
+
*/
|
|
14
|
+
export interface CachingDictionary {
|
|
15
|
+
name: string;
|
|
16
|
+
id: number;
|
|
17
|
+
has(word: string): boolean;
|
|
18
|
+
isNoSuggestWord(word: string): boolean;
|
|
19
|
+
isForbidden(word: string): boolean;
|
|
20
|
+
stats(): CallStats;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* create a caching dictionary
|
|
24
|
+
* @param dict - Dictionary to cache the search results.
|
|
25
|
+
* @param options - Search options to use.
|
|
26
|
+
* @returns CachingDictionary
|
|
27
|
+
*/
|
|
28
|
+
export declare function createCachingDictionary(dict: SpellingDictionary | SpellingDictionaryCollection, options: SearchOptions): CachingDictionary;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=CachingDictionary.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCachingDictionary = void 0;
|
|
4
|
+
const AutoCache_1 = require("../util/AutoCache");
|
|
5
|
+
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
6
|
+
let dictionaryCounter = 0;
|
|
7
|
+
class CachedDict {
|
|
8
|
+
constructor(dict, options) {
|
|
9
|
+
this.dict = dict;
|
|
10
|
+
this.options = options;
|
|
11
|
+
this.id = ++dictionaryCounter;
|
|
12
|
+
this.has = (0, AutoCache_1.autoCache)((word) => this.dict.has(word, this.options));
|
|
13
|
+
this.isNoSuggestWord = (0, AutoCache_1.autoCache)((word) => this.dict.isNoSuggestWord(word, this.options));
|
|
14
|
+
this.isForbidden = (0, AutoCache_1.autoCache)((word) => this.dict.isForbidden(word));
|
|
15
|
+
this.name = dict.name;
|
|
16
|
+
// console.log(`CachedDict for ${this.name}`);
|
|
17
|
+
}
|
|
18
|
+
stats() {
|
|
19
|
+
return {
|
|
20
|
+
name: this.name,
|
|
21
|
+
id: this.id,
|
|
22
|
+
has: (0, AutoCache_1.extractStats)(this.has),
|
|
23
|
+
isNoSuggestWord: (0, AutoCache_1.extractStats)(this.isNoSuggestWord),
|
|
24
|
+
isForbidden: (0, AutoCache_1.extractStats)(this.isForbidden),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const knownDicts = new Map();
|
|
29
|
+
/**
|
|
30
|
+
* create a caching dictionary
|
|
31
|
+
* @param dict - Dictionary to cache the search results.
|
|
32
|
+
* @param options - Search options to use.
|
|
33
|
+
* @returns CachingDictionary
|
|
34
|
+
*/
|
|
35
|
+
function createCachingDictionary(dict, options) {
|
|
36
|
+
options = (0, SpellingDictionaryMethods_1.canonicalSearchOptions)(options);
|
|
37
|
+
let knownOptions = knownDicts.get(options);
|
|
38
|
+
if (!knownOptions) {
|
|
39
|
+
knownOptions = new WeakMap();
|
|
40
|
+
knownDicts.set(options, knownOptions);
|
|
41
|
+
}
|
|
42
|
+
const known = knownOptions.get(dict);
|
|
43
|
+
if (known)
|
|
44
|
+
return known;
|
|
45
|
+
const cached = new CachedDict(dict, options);
|
|
46
|
+
knownOptions.set(dict, cached);
|
|
47
|
+
return cached;
|
|
48
|
+
}
|
|
49
|
+
exports.createCachingDictionary = createCachingDictionary;
|
|
50
|
+
//# sourceMappingURL=CachingDictionary.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SpellingDictionary } from './SpellingDictionary';
|
|
2
|
+
/**
|
|
3
|
+
* Create a dictionary where all words are to be forbidden.
|
|
4
|
+
* @param wordList - list of words
|
|
5
|
+
* @param name
|
|
6
|
+
* @param source
|
|
7
|
+
* @param options
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function createForbiddenWordsDictionary(wordList: readonly string[], name: string, source: string): SpellingDictionary;
|
|
11
|
+
//# sourceMappingURL=ForbiddenWordsDictionary.d.ts.map
|
|
@@ -0,0 +1,107 @@
|
|
|
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
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SpellingDictionary } from './SpellingDictionary';
|
|
2
|
+
/**
|
|
3
|
+
* Create a dictionary where all words are to be ignored.
|
|
4
|
+
* Ignored words override forbidden words.
|
|
5
|
+
* @param wordList - list of words
|
|
6
|
+
* @param name - name of dictionary
|
|
7
|
+
* @param source - dictionary source
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function createIgnoreWordsDictionary(wordList: readonly string[], name: string, source: string): SpellingDictionary;
|
|
11
|
+
//# sourceMappingURL=IgnoreWordsDictionary.d.ts.map
|
|
@@ -0,0 +1,120 @@
|
|
|
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.createIgnoreWordsDictionary = void 0;
|
|
27
|
+
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
28
|
+
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
29
|
+
const Defaults = __importStar(require("./defaults"));
|
|
30
|
+
const createSpellingDictionary_1 = require("./createSpellingDictionary");
|
|
31
|
+
const NormalizeForm = 'NFC';
|
|
32
|
+
class IgnoreWordsDictionary {
|
|
33
|
+
constructor(name, source, words) {
|
|
34
|
+
this.name = name;
|
|
35
|
+
this.source = source;
|
|
36
|
+
this.containsNoSuggestWords = true;
|
|
37
|
+
this.options = {};
|
|
38
|
+
this.type = 'forbidden';
|
|
39
|
+
this.isDictionaryCaseSensitive = true;
|
|
40
|
+
this.dict = new Set(words);
|
|
41
|
+
this.dictNonStrict = new Set((0, sync_1.pipe)(this.dict, (0, sync_1.opFilter)((w) => w.startsWith('~')), (0, sync_1.opMap)((w) => w.slice(1))));
|
|
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
|
+
const nWord = word.normalize(NormalizeForm);
|
|
52
|
+
if (this.dict.has(nWord))
|
|
53
|
+
return true;
|
|
54
|
+
const lcWord = nWord.toLowerCase();
|
|
55
|
+
if (this.dict.has(lcWord))
|
|
56
|
+
return true;
|
|
57
|
+
const ignoreCase = options?.ignoreCase ?? Defaults.ignoreCase;
|
|
58
|
+
return ignoreCase && (this.dictNonStrict.has(nWord) || this.dictNonStrict.has(lcWord));
|
|
59
|
+
}
|
|
60
|
+
/** A more detailed search for a word, might take longer than `has` */
|
|
61
|
+
find(word, options) {
|
|
62
|
+
const nWord = word.normalize(NormalizeForm);
|
|
63
|
+
if (this.dict.has(nWord))
|
|
64
|
+
return { found: nWord, forbidden: false, noSuggest: true };
|
|
65
|
+
const lcWord = nWord.toLowerCase();
|
|
66
|
+
if (this.dict.has(lcWord))
|
|
67
|
+
return { found: lcWord, forbidden: false, noSuggest: true };
|
|
68
|
+
const ignoreCase = options?.ignoreCase ?? Defaults.ignoreCase;
|
|
69
|
+
if (!ignoreCase)
|
|
70
|
+
return undefined;
|
|
71
|
+
if (this.dictNonStrict.has(nWord))
|
|
72
|
+
return { found: nWord, forbidden: false, noSuggest: true };
|
|
73
|
+
return (this.dictNonStrict.has(lcWord) && { found: lcWord, forbidden: false, noSuggest: true }) || undefined;
|
|
74
|
+
}
|
|
75
|
+
isForbidden(_word) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
isNoSuggestWord(word, options) {
|
|
79
|
+
return this.has(word, options);
|
|
80
|
+
}
|
|
81
|
+
suggest() {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
genSuggestions() {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
mapWord(word) {
|
|
88
|
+
return word;
|
|
89
|
+
}
|
|
90
|
+
get size() {
|
|
91
|
+
return this.dict.size;
|
|
92
|
+
}
|
|
93
|
+
getErrors() {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Create a dictionary where all words are to be ignored.
|
|
99
|
+
* Ignored words override forbidden words.
|
|
100
|
+
* @param wordList - list of words
|
|
101
|
+
* @param name - name of dictionary
|
|
102
|
+
* @param source - dictionary source
|
|
103
|
+
* @returns
|
|
104
|
+
*/
|
|
105
|
+
function createIgnoreWordsDictionary(wordList, name, source) {
|
|
106
|
+
const testSpecialCharacters = /[*+]/;
|
|
107
|
+
const words = [...(0, cspell_trie_lib_1.parseDictionaryLines)(wordList, { stripCaseAndAccents: true })].map((w) => w.normalize(NormalizeForm));
|
|
108
|
+
const hasSpecial = words.findIndex((word) => testSpecialCharacters.test(word)) >= 0;
|
|
109
|
+
if (hasSpecial) {
|
|
110
|
+
return (0, createSpellingDictionary_1.createSpellingDictionary)(words, name, source, {
|
|
111
|
+
caseSensitive: true,
|
|
112
|
+
noSuggest: true,
|
|
113
|
+
weightMap: undefined,
|
|
114
|
+
supportNonStrictSearches: true,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return new IgnoreWordsDictionary(name, source, words);
|
|
118
|
+
}
|
|
119
|
+
exports.createIgnoreWordsDictionary = createIgnoreWordsDictionary;
|
|
120
|
+
//# sourceMappingURL=IgnoreWordsDictionary.js.map
|
|
@@ -47,13 +47,18 @@ export interface FindResult {
|
|
|
47
47
|
export declare type HasOptions = SearchOptions;
|
|
48
48
|
export interface SpellingDictionaryOptions {
|
|
49
49
|
repMap?: ReplaceMap;
|
|
50
|
-
useCompounds?: boolean;
|
|
51
50
|
/**
|
|
52
51
|
* The dictionary is case aware.
|
|
53
52
|
*/
|
|
54
53
|
caseSensitive?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* This is a NO Suggest dictionary used for words to be ignored.
|
|
56
|
+
*/
|
|
55
57
|
noSuggest?: boolean;
|
|
56
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Extra dictionary information used in improving suggestions
|
|
60
|
+
* based upon locale.
|
|
61
|
+
*/
|
|
57
62
|
dictionaryInformation?: DictionaryInformation;
|
|
58
63
|
/**
|
|
59
64
|
* Strip Case and Accents to allow for case insensitive searches and
|
|
@@ -65,6 +70,15 @@ export interface SpellingDictionaryOptions {
|
|
|
65
70
|
* @default true
|
|
66
71
|
*/
|
|
67
72
|
supportNonStrictSearches?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Turns on legacy word compounds.
|
|
75
|
+
* @deprecated
|
|
76
|
+
*/
|
|
77
|
+
useCompounds?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Optional WeightMap used to improve suggestions.
|
|
80
|
+
*/
|
|
81
|
+
weightMap?: WeightMap | undefined;
|
|
68
82
|
}
|
|
69
83
|
export interface DictionaryInfo {
|
|
70
84
|
/** The name of the dictionary */
|
|
@@ -1,31 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { SearchOptions, SpellingDictionary } from './SpellingDictionary';
|
|
2
|
+
export interface SpellingDictionaryCollection extends SpellingDictionary {
|
|
3
|
+
readonly type: 'SpellingDictionaryCollection';
|
|
4
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
5
|
getErrors(): Error[];
|
|
23
|
-
private _isForbiddenInDict;
|
|
24
|
-
private _isNoSuggestWord;
|
|
25
6
|
}
|
|
26
7
|
export declare function createCollection(dictionaries: SpellingDictionary[], name: string): SpellingDictionaryCollection;
|
|
27
8
|
declare function isWordInAnyDictionary(dicts: SpellingDictionary[], word: string, options: SearchOptions): SpellingDictionary | undefined;
|
|
28
9
|
declare function isWordForbiddenInAnyDictionary(dicts: SpellingDictionary[], word: string): SpellingDictionary | undefined;
|
|
10
|
+
export declare function isSpellingDictionaryCollection(dict: SpellingDictionary): dict is SpellingDictionaryCollection;
|
|
29
11
|
export declare const __testing__: {
|
|
30
12
|
isWordInAnyDictionary: typeof isWordInAnyDictionary;
|
|
31
13
|
isWordForbiddenInAnyDictionary: typeof isWordForbiddenInAnyDictionary;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.__testing__ = exports.
|
|
3
|
+
exports.__testing__ = exports.isSpellingDictionaryCollection = exports.createCollection = void 0;
|
|
4
4
|
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
5
|
const gensequence_1 = require("gensequence");
|
|
6
6
|
const util_1 = require("../util/util");
|
|
@@ -10,7 +10,7 @@ const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
|
10
10
|
function identityString(w) {
|
|
11
11
|
return w;
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class SpellingDictionaryCollectionImpl {
|
|
14
14
|
constructor(dictionaries, name) {
|
|
15
15
|
this.dictionaries = dictionaries;
|
|
16
16
|
this.name = name;
|
|
@@ -80,9 +80,8 @@ class SpellingDictionaryCollection {
|
|
|
80
80
|
return this.dictionaries.reduce((errors, dict) => errors.concat(dict.getErrors?.() || []), []);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
exports.SpellingDictionaryCollection = SpellingDictionaryCollection;
|
|
84
83
|
function createCollection(dictionaries, name) {
|
|
85
|
-
return new
|
|
84
|
+
return new SpellingDictionaryCollectionImpl(dictionaries, name);
|
|
86
85
|
}
|
|
87
86
|
exports.createCollection = createCollection;
|
|
88
87
|
function isWordInAnyDictionary(dicts, word, options) {
|
|
@@ -104,6 +103,10 @@ function isNoSuggestWordInAnyDictionary(dicts, word, options) {
|
|
|
104
103
|
function isWordForbiddenInAnyDictionary(dicts, word) {
|
|
105
104
|
return (0, gensequence_1.genSequence)(dicts).first((dict) => dict.isForbidden(word));
|
|
106
105
|
}
|
|
106
|
+
function isSpellingDictionaryCollection(dict) {
|
|
107
|
+
return dict instanceof SpellingDictionaryCollectionImpl;
|
|
108
|
+
}
|
|
109
|
+
exports.isSpellingDictionaryCollection = isSpellingDictionaryCollection;
|
|
107
110
|
exports.__testing__ = {
|
|
108
111
|
isWordInAnyDictionary,
|
|
109
112
|
isWordForbiddenInAnyDictionary,
|
|
@@ -14,7 +14,6 @@ export declare class SpellingDictionaryFromTrie implements SpellingDictionary {
|
|
|
14
14
|
readonly type = "SpellingDictionaryFromTrie";
|
|
15
15
|
readonly isDictionaryCaseSensitive: boolean;
|
|
16
16
|
readonly containsNoSuggestWords: boolean;
|
|
17
|
-
readonly ignoreCharactersRegExp: RegExp | undefined;
|
|
18
17
|
private weightMap;
|
|
19
18
|
constructor(trie: Trie, name: string, options: SpellingDictionaryOptions, source?: string, size?: number);
|
|
20
19
|
get size(): number;
|
|
@@ -26,11 +25,25 @@ export declare class SpellingDictionaryFromTrie implements SpellingDictionary {
|
|
|
26
25
|
private _findAnyForm;
|
|
27
26
|
isNoSuggestWord(word: string, options?: HasOptions): boolean;
|
|
28
27
|
isForbidden(word: string): boolean;
|
|
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[];
|
|
31
31
|
private _suggest;
|
|
32
32
|
genSuggestions(collector: SuggestionCollector, suggestOptions: SuggestOptions): void;
|
|
33
33
|
getErrors(): Error[];
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Create a dictionary from a trie file.
|
|
37
|
+
* @param data - contents of a trie file.
|
|
38
|
+
* @param name - name of dictionary
|
|
39
|
+
* @param source - filename or uri
|
|
40
|
+
* @param options - options.
|
|
41
|
+
* @returns SpellingDictionary
|
|
42
|
+
*/
|
|
43
|
+
export declare function createSpellingDictionaryFromTrieFile(data: Iterable<string> | string, name: string, source: string, options: SpellingDictionaryOptions): SpellingDictionary;
|
|
44
|
+
declare function outerWordForms(word: string, mapWord: (word: string) => string): Set<string>;
|
|
45
|
+
export declare const __testing__: {
|
|
46
|
+
outerWordForms: typeof outerWordForms;
|
|
47
|
+
};
|
|
48
|
+
export {};
|
|
36
49
|
//# sourceMappingURL=SpellingDictionaryFromTrie.d.ts.map
|
|
@@ -1,11 +1,38 @@
|
|
|
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
|
-
exports.
|
|
26
|
+
exports.__testing__ = exports.createSpellingDictionaryFromTrieFile = exports.SpellingDictionaryFromTrie = void 0;
|
|
4
27
|
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
28
|
const repMap_1 = require("../util/repMap");
|
|
6
29
|
const clean_1 = require("../util/clean");
|
|
7
|
-
const charset_1 = require("./charset");
|
|
8
30
|
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
31
|
+
const AutoCache_1 = require("../util/AutoCache");
|
|
32
|
+
const sync_1 = require("@cspell/cspell-pipe/sync");
|
|
33
|
+
const Defaults = __importStar(require("./defaults"));
|
|
34
|
+
const findWordOptionsCaseSensitive = Object.freeze({ caseSensitive: true });
|
|
35
|
+
const findWordOptionsNotCaseSensitive = Object.freeze({ caseSensitive: false });
|
|
9
36
|
class SpellingDictionaryFromTrie {
|
|
10
37
|
constructor(trie, name, options, source = 'from trie', size) {
|
|
11
38
|
this.trie = trie;
|
|
@@ -16,13 +43,15 @@ class SpellingDictionaryFromTrie {
|
|
|
16
43
|
this.knownWords = new Set();
|
|
17
44
|
this.unknownWords = new Set();
|
|
18
45
|
this.type = 'SpellingDictionaryFromTrie';
|
|
19
|
-
this._find = (word, useCompounds, ignoreCase) => this.findAnyForm(word, useCompounds, ignoreCase);
|
|
20
|
-
this.
|
|
46
|
+
this._find = findCache((word, useCompounds, ignoreCase) => this.findAnyForm(word, useCompounds, ignoreCase));
|
|
47
|
+
this._isForbidden = (0, AutoCache_1.autoCache)((word) => {
|
|
48
|
+
return this.trie.isForbiddenWord(word);
|
|
49
|
+
});
|
|
50
|
+
this.mapWord = (0, repMap_1.createMapper)(options.repMap, options.dictionaryInformation?.ignore);
|
|
21
51
|
this.isDictionaryCaseSensitive = options.caseSensitive ?? !trie.isLegacy;
|
|
22
52
|
this.containsNoSuggestWords = options.noSuggest || false;
|
|
23
53
|
this._size = size || 0;
|
|
24
54
|
this.weightMap = options.weightMap || (0, SpellingDictionaryMethods_1.createWeightMapFromDictionaryInformation)(options.dictionaryInformation);
|
|
25
|
-
this.ignoreCharactersRegExp = (0, charset_1.charsetToRegExp)(this.options.dictionaryInformation?.ignore);
|
|
26
55
|
}
|
|
27
56
|
get size() {
|
|
28
57
|
if (!this._size) {
|
|
@@ -56,16 +85,11 @@ class SpellingDictionaryFromTrie {
|
|
|
56
85
|
return { found, forbidden, noSuggest };
|
|
57
86
|
}
|
|
58
87
|
resolveOptions(hasOptions) {
|
|
59
|
-
const { useCompounds = this.options.useCompounds, ignoreCase =
|
|
88
|
+
const { useCompounds = this.options.useCompounds, ignoreCase = Defaults.ignoreCase } = (0, SpellingDictionaryMethods_1.hasOptionToSearchOption)(hasOptions);
|
|
60
89
|
return { useCompounds, ignoreCase };
|
|
61
90
|
}
|
|
62
91
|
findAnyForm(word, useCompounds, ignoreCase) {
|
|
63
|
-
const outerForms =
|
|
64
|
-
if (this.ignoreCharactersRegExp) {
|
|
65
|
-
outerForms.add(word.replace(this.ignoreCharactersRegExp, ''));
|
|
66
|
-
outerForms.add(word.normalize('NFD').replace(this.ignoreCharactersRegExp, ''));
|
|
67
|
-
outerForms.add(word.normalize('NFC').replace(this.ignoreCharactersRegExp, ''));
|
|
68
|
-
}
|
|
92
|
+
const outerForms = outerWordForms(word, this.mapWord);
|
|
69
93
|
for (const form of outerForms) {
|
|
70
94
|
const r = this._findAnyForm(form, useCompounds, ignoreCase);
|
|
71
95
|
if (r)
|
|
@@ -73,9 +97,8 @@ class SpellingDictionaryFromTrie {
|
|
|
73
97
|
}
|
|
74
98
|
return undefined;
|
|
75
99
|
}
|
|
76
|
-
_findAnyForm(
|
|
77
|
-
const
|
|
78
|
-
const opts = { caseSensitive: !ignoreCase };
|
|
100
|
+
_findAnyForm(mWord, useCompounds, ignoreCase) {
|
|
101
|
+
const opts = ignoreCase ? findWordOptionsNotCaseSensitive : findWordOptionsCaseSensitive;
|
|
79
102
|
const findResult = this.trie.findWord(mWord, opts);
|
|
80
103
|
if (findResult.found !== false) {
|
|
81
104
|
return findResult;
|
|
@@ -88,9 +111,9 @@ class SpellingDictionaryFromTrie {
|
|
|
88
111
|
}
|
|
89
112
|
}
|
|
90
113
|
if (useCompounds) {
|
|
91
|
-
opts
|
|
114
|
+
const optsUseCompounds = { ...opts, useLegacyWordCompounds: useCompounds };
|
|
92
115
|
for (const w of forms) {
|
|
93
|
-
const findResult = this.trie.findWord(w,
|
|
116
|
+
const findResult = this.trie.findWord(w, optsUseCompounds);
|
|
94
117
|
if (findResult.found !== false) {
|
|
95
118
|
return findResult;
|
|
96
119
|
}
|
|
@@ -102,7 +125,7 @@ class SpellingDictionaryFromTrie {
|
|
|
102
125
|
return this.containsNoSuggestWords ? this.has(word, options) : false;
|
|
103
126
|
}
|
|
104
127
|
isForbidden(word) {
|
|
105
|
-
return this.
|
|
128
|
+
return this._isForbidden(word);
|
|
106
129
|
}
|
|
107
130
|
suggest(...args) {
|
|
108
131
|
const [word] = args;
|
|
@@ -139,10 +162,39 @@ class SpellingDictionaryFromTrie {
|
|
|
139
162
|
}
|
|
140
163
|
exports.SpellingDictionaryFromTrie = SpellingDictionaryFromTrie;
|
|
141
164
|
SpellingDictionaryFromTrie.cachedWordsLimit = 50000;
|
|
142
|
-
|
|
165
|
+
/**
|
|
166
|
+
* Create a dictionary from a trie file.
|
|
167
|
+
* @param data - contents of a trie file.
|
|
168
|
+
* @param name - name of dictionary
|
|
169
|
+
* @param source - filename or uri
|
|
170
|
+
* @param options - options.
|
|
171
|
+
* @returns SpellingDictionary
|
|
172
|
+
*/
|
|
173
|
+
function createSpellingDictionaryFromTrieFile(data, name, source, options) {
|
|
174
|
+
data = typeof data === 'string' ? data.split('\n') : data;
|
|
143
175
|
const trieNode = (0, cspell_trie_lib_1.importTrie)(data);
|
|
144
176
|
const trie = new cspell_trie_lib_1.Trie(trieNode);
|
|
145
177
|
return new SpellingDictionaryFromTrie(trie, name, options, source);
|
|
146
178
|
}
|
|
147
|
-
exports.
|
|
179
|
+
exports.createSpellingDictionaryFromTrieFile = createSpellingDictionaryFromTrieFile;
|
|
180
|
+
function findCache(fn, size = 2000) {
|
|
181
|
+
const cache = (0, AutoCache_1.createCache01)(size);
|
|
182
|
+
function find(word, useCompounds, ignoreCase) {
|
|
183
|
+
const r = cache.get(word);
|
|
184
|
+
if (r !== undefined) {
|
|
185
|
+
if (r.useCompounds === useCompounds && r.ignoreCase === ignoreCase) {
|
|
186
|
+
return r.findResult;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const findResult = fn(word, useCompounds, ignoreCase);
|
|
190
|
+
cache.set(word, { useCompounds, ignoreCase, findResult });
|
|
191
|
+
return findResult;
|
|
192
|
+
}
|
|
193
|
+
return find;
|
|
194
|
+
}
|
|
195
|
+
function outerWordForms(word, mapWord) {
|
|
196
|
+
const forms = (0, sync_1.pipe)([word], (0, sync_1.opConcatMap)((word) => [word, word.normalize('NFC'), word.normalize('NFD')]), (0, sync_1.opConcatMap)((word) => [word, mapWord(word)]));
|
|
197
|
+
return new Set(forms);
|
|
198
|
+
}
|
|
199
|
+
exports.__testing__ = { outerWordForms };
|
|
148
200
|
//# sourceMappingURL=SpellingDictionaryFromTrie.js.map
|
|
@@ -9,13 +9,13 @@ declare function wordSearchFormsArray(word: string, isDictionaryCaseSensitive: b
|
|
|
9
9
|
export declare function wordSearchForms(word: string, isDictionaryCaseSensitive: boolean, ignoreCase: boolean): Set<string>;
|
|
10
10
|
export declare function wordSuggestFormsArray(word: string): string[];
|
|
11
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
12
|
export declare function hasOptionToSearchOption(opt: HasOptions | undefined): SearchOptions;
|
|
13
|
+
/**
|
|
14
|
+
* Find the canonical form for SearchOptions. Useful Maps and WeakMaps.
|
|
15
|
+
* @param opt - options to normalize
|
|
16
|
+
* @returns SearchOptions - the canonical form
|
|
17
|
+
*/
|
|
18
|
+
export declare function canonicalSearchOptions(opt: SearchOptions): SearchOptions;
|
|
19
19
|
export declare function suggestArgsToSuggestOptions(args: SuggestArgs): SuggestOptions;
|
|
20
20
|
export declare function createWeightMapFromDictionaryInformation(di: undefined): undefined;
|
|
21
21
|
export declare function createWeightMapFromDictionaryInformation(di: DictionaryInformation): WeightMap;
|
|
@@ -23,7 +23,5 @@ export declare function createWeightMapFromDictionaryInformation(di: DictionaryI
|
|
|
23
23
|
export declare const __testMethods__: {
|
|
24
24
|
wordSearchForms: typeof wordSearchForms;
|
|
25
25
|
wordSearchFormsArray: typeof wordSearchFormsArray;
|
|
26
|
-
wordDictionaryForms: typeof wordDictionaryForms;
|
|
27
|
-
wordDictionaryFormsCollector: typeof wordDictionaryFormsCollector;
|
|
28
26
|
};
|
|
29
27
|
//# sourceMappingURL=SpellingDictionaryMethods.d.ts.map
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.__testMethods__ = exports.createWeightMapFromDictionaryInformation = exports.suggestArgsToSuggestOptions = exports.
|
|
3
|
+
exports.__testMethods__ = exports.createWeightMapFromDictionaryInformation = exports.suggestArgsToSuggestOptions = exports.canonicalSearchOptions = exports.hasOptionToSearchOption = exports.wordSuggestForms = exports.wordSuggestFormsArray = exports.wordSearchForms = exports.defaultNumSuggestions = exports.suggestionCollector = exports.impersonateCollector = void 0;
|
|
4
4
|
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
5
|
const clean_1 = require("../util/clean");
|
|
6
|
-
const gensequence_1 = require("gensequence");
|
|
7
6
|
const text_1 = require("../util/text");
|
|
8
7
|
var cspell_trie_lib_2 = require("cspell-trie-lib");
|
|
9
8
|
Object.defineProperty(exports, "impersonateCollector", { enumerable: true, get: function () { return cspell_trie_lib_2.impersonateCollector; } });
|
|
@@ -23,7 +22,7 @@ function wordSearchForms(word, isDictionaryCaseSensitive, ignoreCase) {
|
|
|
23
22
|
else {
|
|
24
23
|
forms.add(wordLc);
|
|
25
24
|
// Legacy remove any unbound accents
|
|
26
|
-
forms.add(
|
|
25
|
+
forms.add((0, text_1.removeUnboundAccents)(wordLc));
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
28
|
else {
|
|
@@ -38,7 +37,7 @@ function wordSearchForms(word, isDictionaryCaseSensitive, ignoreCase) {
|
|
|
38
37
|
else {
|
|
39
38
|
forms.add(wordLc);
|
|
40
39
|
// Legacy remove any unbound accents
|
|
41
|
-
forms.add(
|
|
40
|
+
forms.add((0, text_1.removeUnboundAccents)(wordLc));
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
return forms;
|
|
@@ -56,36 +55,37 @@ function wordSuggestForms(word) {
|
|
|
56
55
|
return forms;
|
|
57
56
|
}
|
|
58
57
|
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
58
|
const DEFAULT_HAS_OPTIONS = Object.freeze({});
|
|
85
59
|
function hasOptionToSearchOption(opt) {
|
|
86
|
-
return !opt ? DEFAULT_HAS_OPTIONS : opt;
|
|
60
|
+
return canonicalSearchOptions(!opt ? DEFAULT_HAS_OPTIONS : opt);
|
|
87
61
|
}
|
|
88
62
|
exports.hasOptionToSearchOption = hasOptionToSearchOption;
|
|
63
|
+
const canonicalSearchOptionsMap = new Map();
|
|
64
|
+
const knownCanonicalOptions = new WeakMap();
|
|
65
|
+
/**
|
|
66
|
+
* Find the canonical form for SearchOptions. Useful Maps and WeakMaps.
|
|
67
|
+
* @param opt - options to normalize
|
|
68
|
+
* @returns SearchOptions - the canonical form
|
|
69
|
+
*/
|
|
70
|
+
function canonicalSearchOptions(opt) {
|
|
71
|
+
const known = knownCanonicalOptions.get(opt);
|
|
72
|
+
if (known)
|
|
73
|
+
return known;
|
|
74
|
+
const { ignoreCase, useCompounds } = opt;
|
|
75
|
+
const foundLevel1Map = canonicalSearchOptionsMap.get(ignoreCase);
|
|
76
|
+
const useLevel1Map = foundLevel1Map || new Map();
|
|
77
|
+
if (!foundLevel1Map) {
|
|
78
|
+
canonicalSearchOptionsMap.set(ignoreCase, useLevel1Map);
|
|
79
|
+
}
|
|
80
|
+
const foundCanOpts = useLevel1Map.get(useCompounds);
|
|
81
|
+
const canOpts = foundCanOpts || Object.freeze({ ignoreCase, useCompounds });
|
|
82
|
+
if (!foundCanOpts) {
|
|
83
|
+
useLevel1Map.set(useCompounds, canOpts);
|
|
84
|
+
}
|
|
85
|
+
knownCanonicalOptions.set(opt, canOpts);
|
|
86
|
+
return canOpts;
|
|
87
|
+
}
|
|
88
|
+
exports.canonicalSearchOptions = canonicalSearchOptions;
|
|
89
89
|
function suggestArgsToSuggestOptions(args) {
|
|
90
90
|
const [_word, options, compoundMethod, numChanges, ignoreCase] = args;
|
|
91
91
|
const suggestOptions = typeof options === 'object'
|
|
@@ -108,7 +108,5 @@ exports.createWeightMapFromDictionaryInformation = createWeightMapFromDictionary
|
|
|
108
108
|
exports.__testMethods__ = {
|
|
109
109
|
wordSearchForms,
|
|
110
110
|
wordSearchFormsArray,
|
|
111
|
-
wordDictionaryForms,
|
|
112
|
-
wordDictionaryFormsCollector,
|
|
113
111
|
};
|
|
114
112
|
//# sourceMappingURL=SpellingDictionaryMethods.js.map
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { IterableLike } from '../util/IterableLike';
|
|
2
|
-
import { SpellingDictionary, SpellingDictionaryOptions
|
|
3
|
-
export declare
|
|
4
|
-
|
|
2
|
+
import type { DictionaryInfo, SpellingDictionary, SpellingDictionaryOptions } from './SpellingDictionary';
|
|
3
|
+
export declare const defaultOptions: SpellingDictionaryOptions;
|
|
4
|
+
/**
|
|
5
|
+
* Create a SpellingDictionary
|
|
6
|
+
* @param wordList - list of words
|
|
7
|
+
* @param name - name of dictionary
|
|
8
|
+
* @param source - filename or uri
|
|
9
|
+
* @param options - dictionary options
|
|
10
|
+
* @returns a Spelling Dictionary
|
|
11
|
+
*/
|
|
12
|
+
export declare function createSpellingDictionary(wordList: readonly string[] | IterableLike<string>, name: string, source: string, options?: SpellingDictionaryOptions | undefined): SpellingDictionary;
|
|
5
13
|
export interface SpellingDictionaryLoadError extends Error {
|
|
6
14
|
/** The Error Name */
|
|
7
15
|
readonly name: string;
|
|
@@ -12,6 +20,5 @@ export interface SpellingDictionaryLoadError extends Error {
|
|
|
12
20
|
/** Dictionary Information */
|
|
13
21
|
readonly info: DictionaryInfo;
|
|
14
22
|
}
|
|
15
|
-
export declare function createFailedToLoadDictionary(error:
|
|
16
|
-
export declare function createSpellingDictionaryLoadError(errorName: string, message: string, info: DictionaryInfo, cause?: Error): SpellingDictionaryLoadError;
|
|
23
|
+
export declare function createFailedToLoadDictionary(name: string, source: string, error: Error, options?: SpellingDictionaryOptions | undefined): SpellingDictionary;
|
|
17
24
|
//# sourceMappingURL=createSpellingDictionary.d.ts.map
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createFailedToLoadDictionary = exports.createSpellingDictionary = exports.defaultOptions = void 0;
|
|
4
4
|
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
5
|
const fast_equals_1 = require("fast-equals");
|
|
6
|
-
const gensequence_1 = require("gensequence");
|
|
7
6
|
const simpleCache_1 = require("../util/simpleCache");
|
|
8
7
|
const SpellingDictionaryFromTrie_1 = require("./SpellingDictionaryFromTrie");
|
|
9
8
|
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
10
|
-
|
|
9
|
+
exports.defaultOptions = Object.freeze({
|
|
11
10
|
weightMap: undefined,
|
|
12
11
|
});
|
|
13
12
|
const cachedDictionaries = new simpleCache_1.AutoWeakCache(_createSpellingDictionary, 64);
|
|
14
13
|
const maxSetSize = 3;
|
|
15
14
|
const cachedParamsByWordList = new simpleCache_1.SimpleCache(64);
|
|
15
|
+
/**
|
|
16
|
+
* Create a SpellingDictionary
|
|
17
|
+
* @param wordList - list of words
|
|
18
|
+
* @param name - name of dictionary
|
|
19
|
+
* @param source - filename or uri
|
|
20
|
+
* @param options - dictionary options
|
|
21
|
+
* @returns a Spelling Dictionary
|
|
22
|
+
*/
|
|
16
23
|
function createSpellingDictionary(wordList, name, source, options) {
|
|
17
24
|
const params = [wordList, name, source, options];
|
|
18
25
|
if (!Array.isArray(wordList)) {
|
|
@@ -37,24 +44,14 @@ function _createSpellingDictionary(params) {
|
|
|
37
44
|
const parseOptions = { stripCaseAndAccents: options?.supportNonStrictSearches ?? true };
|
|
38
45
|
const words = (0, cspell_trie_lib_1.parseDictionaryLines)(wordList, parseOptions);
|
|
39
46
|
const trie = (0, cspell_trie_lib_1.buildTrieFast)(words);
|
|
40
|
-
const opts = { ...(options || defaultOptions) };
|
|
47
|
+
const opts = { ...(options || exports.defaultOptions) };
|
|
41
48
|
if (opts.weightMap === undefined && opts.dictionaryInformation) {
|
|
42
49
|
opts.weightMap = (0, SpellingDictionaryMethods_1.createWeightMapFromDictionaryInformation)(opts.dictionaryInformation);
|
|
43
50
|
}
|
|
44
51
|
return new SpellingDictionaryFromTrie_1.SpellingDictionaryFromTrie(trie, name, opts, source);
|
|
45
52
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
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 { name, source, options } = error.info;
|
|
53
|
+
function createFailedToLoadDictionary(name, source, error, options) {
|
|
54
|
+
options = options || {};
|
|
58
55
|
return {
|
|
59
56
|
name,
|
|
60
57
|
source,
|
|
@@ -76,16 +73,4 @@ function createFailedToLoadDictionary(error) {
|
|
|
76
73
|
};
|
|
77
74
|
}
|
|
78
75
|
exports.createFailedToLoadDictionary = createFailedToLoadDictionary;
|
|
79
|
-
function createSpellingDictionaryLoadError(errorName, message, info, cause) {
|
|
80
|
-
const err = {
|
|
81
|
-
name: errorName,
|
|
82
|
-
message,
|
|
83
|
-
info,
|
|
84
|
-
cause,
|
|
85
|
-
};
|
|
86
|
-
const stack = cause?.stack;
|
|
87
|
-
stack && (err.stack = stack);
|
|
88
|
-
return err;
|
|
89
|
-
}
|
|
90
|
-
exports.createSpellingDictionaryLoadError = createSpellingDictionaryLoadError;
|
|
91
76
|
//# sourceMappingURL=createSpellingDictionary.js.map
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { CachingDictionary, createCachingDictionary } from './CachingDictionary';
|
|
2
|
+
export { createSpellingDictionary } from './createSpellingDictionary';
|
|
3
|
+
export { createForbiddenWordsDictionary } from './ForbiddenWordsDictionary';
|
|
4
|
+
export { createIgnoreWordsDictionary } from './IgnoreWordsDictionary';
|
|
2
5
|
export type { FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary';
|
|
3
|
-
export { createCollection } from './SpellingDictionaryCollection';
|
|
6
|
+
export { createCollection, SpellingDictionaryCollection } from './SpellingDictionaryCollection';
|
|
7
|
+
export { createSpellingDictionaryFromTrieFile } from './SpellingDictionaryFromTrie';
|
|
4
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCollection = exports.
|
|
3
|
+
exports.createSpellingDictionaryFromTrieFile = exports.createCollection = exports.createIgnoreWordsDictionary = exports.createForbiddenWordsDictionary = exports.createSpellingDictionary = exports.createCachingDictionary = void 0;
|
|
4
|
+
var CachingDictionary_1 = require("./CachingDictionary");
|
|
5
|
+
Object.defineProperty(exports, "createCachingDictionary", { enumerable: true, get: function () { return CachingDictionary_1.createCachingDictionary; } });
|
|
4
6
|
var createSpellingDictionary_1 = require("./createSpellingDictionary");
|
|
5
|
-
Object.defineProperty(exports, "createForbiddenWordsDictionary", { enumerable: true, get: function () { return createSpellingDictionary_1.createForbiddenWordsDictionary; } });
|
|
6
7
|
Object.defineProperty(exports, "createSpellingDictionary", { enumerable: true, get: function () { return createSpellingDictionary_1.createSpellingDictionary; } });
|
|
8
|
+
var ForbiddenWordsDictionary_1 = require("./ForbiddenWordsDictionary");
|
|
9
|
+
Object.defineProperty(exports, "createForbiddenWordsDictionary", { enumerable: true, get: function () { return ForbiddenWordsDictionary_1.createForbiddenWordsDictionary; } });
|
|
10
|
+
var IgnoreWordsDictionary_1 = require("./IgnoreWordsDictionary");
|
|
11
|
+
Object.defineProperty(exports, "createIgnoreWordsDictionary", { enumerable: true, get: function () { return IgnoreWordsDictionary_1.createIgnoreWordsDictionary; } });
|
|
7
12
|
var SpellingDictionaryCollection_1 = require("./SpellingDictionaryCollection");
|
|
8
13
|
Object.defineProperty(exports, "createCollection", { enumerable: true, get: function () { return SpellingDictionaryCollection_1.createCollection; } });
|
|
14
|
+
var SpellingDictionaryFromTrie_1 = require("./SpellingDictionaryFromTrie");
|
|
15
|
+
Object.defineProperty(exports, "createSpellingDictionaryFromTrieFile", { enumerable: true, get: function () { return SpellingDictionaryFromTrie_1.createSpellingDictionaryFromTrieFile; } });
|
|
9
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createCollection, createForbiddenWordsDictionary, createSpellingDictionary } from './SpellingDictionary';
|
|
2
|
-
export type { FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary';
|
|
1
|
+
export { createCachingDictionary, createCollection, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, SpellingDictionaryCollection, } from './SpellingDictionary';
|
|
2
|
+
export type { CachingDictionary, FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSpellingDictionary = exports.createForbiddenWordsDictionary = exports.createCollection = void 0;
|
|
3
|
+
exports.createSpellingDictionaryFromTrieFile = exports.createSpellingDictionary = exports.createIgnoreWordsDictionary = exports.createForbiddenWordsDictionary = exports.createCollection = exports.createCachingDictionary = void 0;
|
|
4
4
|
var SpellingDictionary_1 = require("./SpellingDictionary");
|
|
5
|
+
Object.defineProperty(exports, "createCachingDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createCachingDictionary; } });
|
|
5
6
|
Object.defineProperty(exports, "createCollection", { enumerable: true, get: function () { return SpellingDictionary_1.createCollection; } });
|
|
6
7
|
Object.defineProperty(exports, "createForbiddenWordsDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createForbiddenWordsDictionary; } });
|
|
8
|
+
Object.defineProperty(exports, "createIgnoreWordsDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createIgnoreWordsDictionary; } });
|
|
7
9
|
Object.defineProperty(exports, "createSpellingDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createSpellingDictionary; } });
|
|
10
|
+
Object.defineProperty(exports, "createSpellingDictionaryFromTrieFile", { enumerable: true, get: function () { return SpellingDictionary_1.createSpellingDictionaryFromTrieFile; } });
|
|
8
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
interface AutoCache<R> extends CacheStats {
|
|
2
|
+
(word: string): R;
|
|
3
|
+
}
|
|
4
|
+
export interface CacheStats {
|
|
5
|
+
hits: number;
|
|
6
|
+
misses: number;
|
|
7
|
+
swaps: number;
|
|
8
|
+
}
|
|
9
|
+
declare class Cache01<R> implements CacheStats {
|
|
10
|
+
readonly maxSize: number;
|
|
11
|
+
private count;
|
|
12
|
+
private cache0;
|
|
13
|
+
private cache1;
|
|
14
|
+
hits: number;
|
|
15
|
+
misses: number;
|
|
16
|
+
swaps: number;
|
|
17
|
+
constructor(maxSize: number);
|
|
18
|
+
get(key: string): R | undefined;
|
|
19
|
+
set(key: string, value: R): this;
|
|
20
|
+
}
|
|
21
|
+
export declare function createCache01<R>(size: number): Cache01<R>;
|
|
22
|
+
export declare function autoCache<R>(fn: (p: string) => R, size?: number): AutoCache<R>;
|
|
23
|
+
export declare function extractStats(ac: AutoCache<unknown> | CacheStats): CacheStats;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=AutoCache.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractStats = exports.autoCache = exports.createCache01 = void 0;
|
|
4
|
+
const CACHE_SIZE = 100;
|
|
5
|
+
class Cache01 {
|
|
6
|
+
constructor(maxSize) {
|
|
7
|
+
this.maxSize = maxSize;
|
|
8
|
+
this.count = 0;
|
|
9
|
+
this.cache0 = Object.create(null);
|
|
10
|
+
this.cache1 = Object.create(null);
|
|
11
|
+
this.hits = 0;
|
|
12
|
+
this.misses = 0;
|
|
13
|
+
this.swaps = 0;
|
|
14
|
+
}
|
|
15
|
+
get(key) {
|
|
16
|
+
const cache0 = this.cache0;
|
|
17
|
+
const cache1 = this.cache1;
|
|
18
|
+
if (key in cache0) {
|
|
19
|
+
++this.hits;
|
|
20
|
+
return cache0[key];
|
|
21
|
+
}
|
|
22
|
+
if (key in cache1) {
|
|
23
|
+
++this.hits;
|
|
24
|
+
++this.count;
|
|
25
|
+
const r = cache1[key];
|
|
26
|
+
cache0[key] = r;
|
|
27
|
+
return r;
|
|
28
|
+
}
|
|
29
|
+
++this.misses;
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
set(key, value) {
|
|
33
|
+
if (this.count >= this.maxSize) {
|
|
34
|
+
this.cache1 = this.cache0;
|
|
35
|
+
this.cache0 = Object.create(null);
|
|
36
|
+
this.swaps++;
|
|
37
|
+
this.count = 0;
|
|
38
|
+
}
|
|
39
|
+
++this.count;
|
|
40
|
+
this.cache0[key] = value;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function createCache01(size) {
|
|
45
|
+
return new Cache01(size);
|
|
46
|
+
}
|
|
47
|
+
exports.createCache01 = createCache01;
|
|
48
|
+
function autoCache(fn, size = CACHE_SIZE) {
|
|
49
|
+
const cache = createCache01(size);
|
|
50
|
+
const ac = get;
|
|
51
|
+
ac.hits = 0;
|
|
52
|
+
ac.misses = 0;
|
|
53
|
+
ac.swaps = 0;
|
|
54
|
+
function get(k) {
|
|
55
|
+
const f = cache.get(k);
|
|
56
|
+
if (f !== undefined) {
|
|
57
|
+
++ac.hits;
|
|
58
|
+
return f;
|
|
59
|
+
}
|
|
60
|
+
const r = fn(k);
|
|
61
|
+
cache.set(k, r);
|
|
62
|
+
ac.swaps = cache.swaps;
|
|
63
|
+
++ac.misses;
|
|
64
|
+
return r;
|
|
65
|
+
}
|
|
66
|
+
return ac;
|
|
67
|
+
}
|
|
68
|
+
exports.autoCache = autoCache;
|
|
69
|
+
function extractStats(ac) {
|
|
70
|
+
const { hits, misses, swaps } = ac;
|
|
71
|
+
return { hits, misses, swaps };
|
|
72
|
+
}
|
|
73
|
+
exports.extractStats = extractStats;
|
|
74
|
+
//# sourceMappingURL=AutoCache.js.map
|
package/dist/util/repMap.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import type { ReplaceMap } from '@cspell/cspell-types';
|
|
1
|
+
import type { CharacterSet, ReplaceMap } from '@cspell/cspell-types';
|
|
2
2
|
export declare type ReplaceMapper = (src: string) => string;
|
|
3
|
-
export declare function createMapper(repMap: ReplaceMap): ReplaceMapper;
|
|
3
|
+
export declare function createMapper(repMap: ReplaceMap | undefined, ignoreCharset?: string): ReplaceMapper;
|
|
4
|
+
declare function charsetToRepMap(charset: CharacterSet | undefined, replaceWith?: string): ReplaceMap | undefined;
|
|
5
|
+
declare function createMapperRegExp(repMap: ReplaceMap): RegExp;
|
|
6
|
+
export declare const __testing__: {
|
|
7
|
+
charsetToRepMap: typeof charsetToRepMap;
|
|
8
|
+
createMapperRegExp: typeof createMapperRegExp;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
4
11
|
//# sourceMappingURL=repMap.d.ts.map
|
package/dist/util/repMap.js
CHANGED
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createMapper = void 0;
|
|
3
|
+
exports.__testing__ = exports.createMapper = void 0;
|
|
4
4
|
const regexHelper_1 = require("./regexHelper");
|
|
5
|
-
function createMapper(repMap) {
|
|
5
|
+
function createMapper(repMap, ignoreCharset) {
|
|
6
|
+
if (!repMap && !ignoreCharset)
|
|
7
|
+
return (a) => a;
|
|
8
|
+
repMap = repMap || [];
|
|
9
|
+
const charsetMap = charsetToRepMap(ignoreCharset);
|
|
10
|
+
if (charsetMap) {
|
|
11
|
+
repMap = repMap.concat(charsetMap);
|
|
12
|
+
}
|
|
6
13
|
const filteredMap = repMap.filter(([match, _]) => !!match);
|
|
7
14
|
if (!filteredMap.length) {
|
|
8
15
|
return (a) => a;
|
|
9
16
|
}
|
|
17
|
+
const regEx = createMapperRegExp(repMap);
|
|
18
|
+
const values = repMap.filter(([match, _]) => !!match).map(([_, into]) => into);
|
|
19
|
+
function resolve(m, ...matches) {
|
|
20
|
+
const index = matches.findIndex((a) => !!a);
|
|
21
|
+
return 0 <= index && index < values.length ? values[index] : m;
|
|
22
|
+
}
|
|
23
|
+
return function (s) {
|
|
24
|
+
return s.replace(regEx, resolve);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.createMapper = createMapper;
|
|
28
|
+
function charsetToRepMap(charset, replaceWith = '') {
|
|
29
|
+
if (!charset)
|
|
30
|
+
return undefined;
|
|
31
|
+
return charset
|
|
32
|
+
.split('|')
|
|
33
|
+
.map((chars) => `[${chars.replace(/[\][\\]/g, '\\$&')}]`)
|
|
34
|
+
.map((map) => [map, replaceWith]);
|
|
35
|
+
}
|
|
36
|
+
function createMapperRegExp(repMap) {
|
|
37
|
+
const filteredMap = repMap.filter(([match, _]) => !!match);
|
|
38
|
+
if (!filteredMap.length) {
|
|
39
|
+
return /$^/;
|
|
40
|
+
}
|
|
10
41
|
const regExStr = filteredMap
|
|
11
42
|
.map(([from, _]) => from)
|
|
12
43
|
// make sure it compiles into a regex
|
|
@@ -25,14 +56,10 @@ function createMapper(repMap) {
|
|
|
25
56
|
.map((s) => `(${s})`)
|
|
26
57
|
.join('|');
|
|
27
58
|
const regEx = new RegExp(regExStr, 'g');
|
|
28
|
-
|
|
29
|
-
function resolve(m, ...matches) {
|
|
30
|
-
const index = matches.findIndex((a) => !!a);
|
|
31
|
-
return 0 <= index && index < values.length ? values[index] : m;
|
|
32
|
-
}
|
|
33
|
-
return function (s) {
|
|
34
|
-
return s.replace(regEx, resolve);
|
|
35
|
-
};
|
|
59
|
+
return regEx;
|
|
36
60
|
}
|
|
37
|
-
exports.
|
|
61
|
+
exports.__testing__ = {
|
|
62
|
+
charsetToRepMap,
|
|
63
|
+
createMapperRegExp,
|
|
64
|
+
};
|
|
38
65
|
//# sourceMappingURL=repMap.js.map
|
package/dist/util/text.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ export declare function ucFirst(word: string): string;
|
|
|
6
6
|
export declare function lcFirst(word: string): string;
|
|
7
7
|
export declare function matchCase(example: string, word: string): string;
|
|
8
8
|
export declare function removeAccents(text: string): string;
|
|
9
|
+
export declare function removeUnboundAccents(text: string): string;
|
|
9
10
|
//# sourceMappingURL=text.d.ts.map
|
package/dist/util/text.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeAccents = exports.matchCase = exports.lcFirst = exports.ucFirst = exports.isFirstCharacterLower = exports.isFirstCharacterUpper = exports.isLowerCase = exports.isUpperCase = void 0;
|
|
3
|
+
exports.removeUnboundAccents = exports.removeAccents = exports.matchCase = exports.lcFirst = exports.ucFirst = exports.isFirstCharacterLower = exports.isFirstCharacterUpper = exports.isLowerCase = exports.isUpperCase = void 0;
|
|
4
4
|
const regExFirstUpper = /^\p{Lu}\p{M}?\p{Ll}+$/u;
|
|
5
5
|
const regExAllUpper = /^(?:\p{Lu}\p{M}?)+$/u;
|
|
6
6
|
const regExAllLower = /^(?:\p{Ll}\p{M}?)+$/u;
|
|
@@ -52,4 +52,8 @@ function removeAccents(text) {
|
|
|
52
52
|
return text.normalize('NFD').replace(regExAccents, '');
|
|
53
53
|
}
|
|
54
54
|
exports.removeAccents = removeAccents;
|
|
55
|
+
function removeUnboundAccents(text) {
|
|
56
|
+
return text.replace(regExAccents, '');
|
|
57
|
+
}
|
|
58
|
+
exports.removeUnboundAccents = removeUnboundAccents;
|
|
55
59
|
//# sourceMappingURL=text.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-dictionary",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.11.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",
|
|
@@ -37,12 +37,17 @@
|
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=14"
|
|
39
39
|
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/jest": "^29.1.0",
|
|
42
|
+
"jest": "^29.1.1",
|
|
43
|
+
"ts-jest": "^29.0.3"
|
|
44
|
+
},
|
|
40
45
|
"dependencies": {
|
|
41
|
-
"@cspell/cspell-pipe": "^6.
|
|
42
|
-
"@cspell/cspell-types": "^6.
|
|
43
|
-
"cspell-trie-lib": "^6.
|
|
46
|
+
"@cspell/cspell-pipe": "^6.11.0",
|
|
47
|
+
"@cspell/cspell-types": "^6.11.0",
|
|
48
|
+
"cspell-trie-lib": "^6.11.0",
|
|
44
49
|
"fast-equals": "^4.0.3",
|
|
45
50
|
"gensequence": "^4.0.2"
|
|
46
51
|
},
|
|
47
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "664676692898c3b6aa150fb2c6656b56f49a54b8"
|
|
48
53
|
}
|
|
@@ -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
|