cspell-dictionary 6.27.0 → 6.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/CachingDictionary.d.ts +3 -3
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/CachingDictionary.js +9 -9
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/FlagWordsDictionary.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/FlagWordsDictionary.js +11 -11
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/IgnoreWordsDictionary.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/IgnoreWordsDictionary.js +5 -5
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionary.d.ts +7 -0
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryCollection.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryCollection.js +12 -12
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryFromTrie.d.ts +3 -2
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryFromTrie.js +18 -17
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryMethods.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryMethods.js +5 -5
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SuggestDictionary.d.ts +2 -2
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SuggestDictionary.js +9 -9
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Terms/index.d.ts +1 -1
- package/dist/cjs/SpellingDictionary/Typos/index.d.ts +4 -0
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/index.js +7 -7
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/typos.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/typosParser.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/typosParser.js +6 -6
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/util.d.ts +1 -1
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/TyposDictionary.d.ts +2 -2
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/TyposDictionary.js +10 -10
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/createInlineSpellingDictionary.d.ts +1 -1
- package/dist/cjs/SpellingDictionary/createInlineSpellingDictionary.js +25 -0
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/createSpellingDictionary.d.ts +2 -2
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/createSpellingDictionary.js +9 -9
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/index.d.ts +10 -10
- package/dist/{SpellingDictionary → cjs/SpellingDictionary}/index.js +20 -20
- package/dist/{index.d.ts → cjs/index.d.ts} +2 -2
- package/dist/{index.js → cjs/index.js} +11 -11
- package/dist/{util → cjs/util}/clean.d.ts +1 -1
- package/dist/cjs/util/repMap.d.ts +27 -0
- package/dist/cjs/util/repMap.js +158 -0
- package/dist/{util → cjs/util}/textMappers.js +2 -2
- package/dist/esm/SpellingDictionary/CachingDictionary.d.mts +30 -0
- package/dist/esm/SpellingDictionary/CachingDictionary.mjs +45 -0
- package/dist/esm/SpellingDictionary/FlagWordsDictionary.d.mts +11 -0
- package/dist/esm/SpellingDictionary/FlagWordsDictionary.mjs +134 -0
- package/dist/esm/SpellingDictionary/IgnoreWordsDictionary.d.mts +11 -0
- package/dist/esm/SpellingDictionary/IgnoreWordsDictionary.mjs +96 -0
- package/dist/esm/SpellingDictionary/SpellingDictionary.d.mts +150 -0
- package/dist/esm/SpellingDictionary/SpellingDictionary.mjs +4 -0
- package/dist/esm/SpellingDictionary/SpellingDictionaryCollection.d.mts +16 -0
- package/dist/esm/SpellingDictionary/SpellingDictionaryCollection.mjs +111 -0
- package/dist/esm/SpellingDictionary/SpellingDictionaryFromTrie.d.mts +50 -0
- package/dist/esm/SpellingDictionary/SpellingDictionaryFromTrie.mjs +172 -0
- package/dist/esm/SpellingDictionary/SpellingDictionaryMethods.d.mts +26 -0
- package/dist/esm/SpellingDictionary/SpellingDictionaryMethods.mjs +96 -0
- package/dist/esm/SpellingDictionary/SuggestDictionary.d.mts +20 -0
- package/dist/esm/SpellingDictionary/SuggestDictionary.mjs +97 -0
- package/dist/esm/SpellingDictionary/Terms/index.d.mts +2 -0
- package/dist/esm/SpellingDictionary/Terms/index.mjs +1 -0
- package/dist/esm/SpellingDictionary/Terms/terms.d.mts +12 -0
- package/dist/esm/SpellingDictionary/Terms/terms.mjs +1 -0
- package/dist/esm/SpellingDictionary/Typos/index.d.mts +4 -0
- package/dist/esm/SpellingDictionary/Typos/index.mjs +2 -0
- package/dist/esm/SpellingDictionary/Typos/typos.d.mts +18 -0
- package/dist/esm/SpellingDictionary/Typos/typos.mjs +1 -0
- package/dist/esm/SpellingDictionary/Typos/typosParser.d.mts +34 -0
- package/dist/esm/SpellingDictionary/Typos/typosParser.mjs +131 -0
- package/dist/esm/SpellingDictionary/Typos/util.d.mts +31 -0
- package/dist/esm/SpellingDictionary/Typos/util.mjs +105 -0
- package/dist/esm/SpellingDictionary/TyposDictionary.d.mts +21 -0
- package/dist/esm/SpellingDictionary/TyposDictionary.mjs +129 -0
- package/dist/esm/SpellingDictionary/createInlineSpellingDictionary.d.mts +3 -0
- package/dist/esm/SpellingDictionary/createInlineSpellingDictionary.mjs +20 -0
- package/dist/esm/SpellingDictionary/createSpellingDictionary.d.mts +23 -0
- package/dist/esm/SpellingDictionary/createSpellingDictionary.mjs +68 -0
- package/dist/esm/SpellingDictionary/defaults.d.mts +3 -0
- package/dist/esm/SpellingDictionary/defaults.mjs +2 -0
- package/dist/esm/SpellingDictionary/index.d.mts +11 -0
- package/dist/esm/SpellingDictionary/index.mjs +9 -0
- package/dist/esm/index.d.mts +3 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/util/AutoCache.d.mts +25 -0
- package/dist/esm/util/AutoCache.mjs +67 -0
- package/dist/esm/util/AutoResolve.d.mts +21 -0
- package/dist/esm/util/AutoResolve.mjs +52 -0
- package/dist/esm/util/IterableLike.d.mts +4 -0
- package/dist/esm/util/IterableLike.mjs +1 -0
- package/dist/esm/util/clean.d.mts +7 -0
- package/dist/esm/util/clean.mjs +13 -0
- package/dist/esm/util/regexHelper.d.mts +7 -0
- package/dist/esm/util/regexHelper.mjs +8 -0
- package/dist/esm/util/repMap.d.mts +27 -0
- package/dist/esm/util/repMap.mjs +152 -0
- package/dist/esm/util/simpleCache.d.mts +46 -0
- package/dist/esm/util/simpleCache.mjs +135 -0
- package/dist/esm/util/text.d.mts +10 -0
- package/dist/esm/util/text.mjs +46 -0
- package/dist/esm/util/textMappers.d.mts +3 -0
- package/dist/esm/util/textMappers.mjs +15 -0
- package/dist/esm/util/types.d.mts +7 -0
- package/dist/esm/util/types.mjs +1 -0
- package/dist/esm/util/util.d.mts +2 -0
- package/dist/esm/util/util.mjs +3 -0
- package/package.json +29 -20
- package/dist/SpellingDictionary/Typos/index.d.ts +0 -4
- package/dist/SpellingDictionary/createInlineSpellingDictionary.js +0 -25
- package/dist/util/repMap.d.ts +0 -11
- package/dist/util/repMap.js +0 -65
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionary.js +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Terms/index.js +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Terms/terms.d.ts +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Terms/terms.js +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/typos.js +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/util.js +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/defaults.d.ts +0 -0
- /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/defaults.js +0 -0
- /package/dist/{util → cjs/util}/AutoCache.d.ts +0 -0
- /package/dist/{util → cjs/util}/AutoCache.js +0 -0
- /package/dist/{util → cjs/util}/AutoResolve.d.ts +0 -0
- /package/dist/{util → cjs/util}/AutoResolve.js +0 -0
- /package/dist/{util → cjs/util}/IterableLike.d.ts +0 -0
- /package/dist/{util → cjs/util}/IterableLike.js +0 -0
- /package/dist/{util → cjs/util}/clean.js +0 -0
- /package/dist/{util → cjs/util}/regexHelper.d.ts +0 -0
- /package/dist/{util → cjs/util}/regexHelper.js +0 -0
- /package/dist/{util → cjs/util}/simpleCache.d.ts +0 -0
- /package/dist/{util → cjs/util}/simpleCache.js +0 -0
- /package/dist/{util → cjs/util}/text.d.ts +0 -0
- /package/dist/{util → cjs/util}/text.js +0 -0
- /package/dist/{util → cjs/util}/textMappers.d.ts +0 -0
- /package/dist/{util → cjs/util}/types.d.ts +0 -0
- /package/dist/{util → cjs/util}/types.js +0 -0
- /package/dist/{util → cjs/util}/util.d.ts +0 -0
- /package/dist/{util → cjs/util}/util.js +0 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { expandCharacterSet } from 'cspell-trie-lib';
|
|
2
|
+
import { escapeRegEx } from './regexHelper.mjs';
|
|
3
|
+
import { isDefined } from './util.mjs';
|
|
4
|
+
export function createMapper(repMap, ignoreCharset) {
|
|
5
|
+
if (!repMap && !ignoreCharset)
|
|
6
|
+
return (a) => a;
|
|
7
|
+
repMap = repMap || [];
|
|
8
|
+
const charsetMap = charsetToRepMapRegEx(ignoreCharset);
|
|
9
|
+
if (charsetMap) {
|
|
10
|
+
repMap = repMap.concat(charsetMap);
|
|
11
|
+
}
|
|
12
|
+
const filteredMap = repMap.filter(([match, _]) => !!match);
|
|
13
|
+
if (!filteredMap.length) {
|
|
14
|
+
return (a) => a;
|
|
15
|
+
}
|
|
16
|
+
const regEx = createMapperRegExp(repMap);
|
|
17
|
+
const values = repMap.filter(([match, _]) => !!match).map(([_, into]) => into);
|
|
18
|
+
function resolve(m, ...matches) {
|
|
19
|
+
const index = matches.findIndex((a) => !!a);
|
|
20
|
+
return 0 <= index && index < values.length ? values[index] : m;
|
|
21
|
+
}
|
|
22
|
+
return function (s) {
|
|
23
|
+
return s.replace(regEx, resolve);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function charsetToRepMapRegEx(charset, replaceWith = '') {
|
|
27
|
+
if (!charset)
|
|
28
|
+
return undefined;
|
|
29
|
+
return charset
|
|
30
|
+
.split('|')
|
|
31
|
+
.map((chars) => `[${chars.replace(/[\][\\]/g, '\\$&')}]`)
|
|
32
|
+
.map((map) => [map, replaceWith]);
|
|
33
|
+
}
|
|
34
|
+
function charsetToRepMap(charset, replaceWith = '') {
|
|
35
|
+
if (!charset)
|
|
36
|
+
return undefined;
|
|
37
|
+
return charset
|
|
38
|
+
.split('|')
|
|
39
|
+
.flatMap((chars) => [...expandCharacterSet(chars)])
|
|
40
|
+
.map((char) => [char, replaceWith]);
|
|
41
|
+
}
|
|
42
|
+
function expandReplaceMap(repMap) {
|
|
43
|
+
return repMap.flatMap(([from, replaceWith]) => from.split('|').map((w) => [w, replaceWith]));
|
|
44
|
+
}
|
|
45
|
+
function createMapperRegExp(repMap) {
|
|
46
|
+
const filteredMap = repMap.filter(([match, _]) => !!match);
|
|
47
|
+
if (!filteredMap.length) {
|
|
48
|
+
return /$^/;
|
|
49
|
+
}
|
|
50
|
+
const regExStr = filteredMap
|
|
51
|
+
.map(([from, _]) => from)
|
|
52
|
+
// make sure it compiles into a regex
|
|
53
|
+
.map((s) => {
|
|
54
|
+
try {
|
|
55
|
+
// fix up any nested ()
|
|
56
|
+
const r = s.match(/\(/) ? s.replace(/\((?=.*\))/g, '(?:').replace(/\(\?:\?/g, '(?') : s;
|
|
57
|
+
new RegExp(r);
|
|
58
|
+
s = r;
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
return escapeRegEx(s);
|
|
62
|
+
}
|
|
63
|
+
return s;
|
|
64
|
+
})
|
|
65
|
+
.map((s) => `(${s})`)
|
|
66
|
+
.join('|');
|
|
67
|
+
const regEx = new RegExp(regExStr, 'g');
|
|
68
|
+
return regEx;
|
|
69
|
+
}
|
|
70
|
+
export function createRepMapper(repMap, ignoreCharset) {
|
|
71
|
+
if (!repMap && !ignoreCharset)
|
|
72
|
+
return (word) => [word];
|
|
73
|
+
const trie = createTrie(repMap, ignoreCharset);
|
|
74
|
+
// const root = createTrie(repMap, ignoreCharset);
|
|
75
|
+
return (word) => {
|
|
76
|
+
const edits = calcAllEdits(trie, word);
|
|
77
|
+
return applyEdits(word, edits);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function applyEdits(word, edits) {
|
|
81
|
+
if (!edits.length)
|
|
82
|
+
return [word];
|
|
83
|
+
// Prepare
|
|
84
|
+
const letterEdits = [];
|
|
85
|
+
for (let i = 0; i < word.length; ++i) {
|
|
86
|
+
letterEdits[i] = { edits: [{ b: i, e: i + 1, r: word[i] }], suffixes: [] };
|
|
87
|
+
}
|
|
88
|
+
letterEdits[word.length] = { edits: [], suffixes: [''] };
|
|
89
|
+
// Add edits
|
|
90
|
+
for (const edit of edits) {
|
|
91
|
+
const le = letterEdits[edit.b];
|
|
92
|
+
le.edits.push(edit);
|
|
93
|
+
}
|
|
94
|
+
// Apply edits in reverse
|
|
95
|
+
for (let i = word.length - 1; i >= 0; --i) {
|
|
96
|
+
const le = letterEdits[i];
|
|
97
|
+
const sfx = le.suffixes;
|
|
98
|
+
for (const edit of le.edits) {
|
|
99
|
+
const pfx = edit.r;
|
|
100
|
+
const nSfx = letterEdits[edit.e].suffixes;
|
|
101
|
+
for (const s of nSfx) {
|
|
102
|
+
sfx.push(pfx + s);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const results = new Set(letterEdits[0].suffixes);
|
|
107
|
+
return [...results];
|
|
108
|
+
}
|
|
109
|
+
function calcAllEdits(root, word) {
|
|
110
|
+
const edits = [];
|
|
111
|
+
function walk(node, b, e) {
|
|
112
|
+
if (node.rep) {
|
|
113
|
+
node.rep.forEach((r) => edits.push({ b, e, r }));
|
|
114
|
+
}
|
|
115
|
+
if (e === word.length || !node.children)
|
|
116
|
+
return;
|
|
117
|
+
const n = node.children[word[e]];
|
|
118
|
+
if (!n)
|
|
119
|
+
return;
|
|
120
|
+
walk(n, b, e + 1);
|
|
121
|
+
}
|
|
122
|
+
for (let i = 0; i < word.length; ++i) {
|
|
123
|
+
walk(root, i, i);
|
|
124
|
+
}
|
|
125
|
+
return edits;
|
|
126
|
+
}
|
|
127
|
+
function createTrie(repMap, ignoreCharset) {
|
|
128
|
+
const combined = [repMap, charsetToRepMap(ignoreCharset)].filter(isDefined).flatMap((a) => a);
|
|
129
|
+
const expanded = expandReplaceMap(combined);
|
|
130
|
+
const trieRoot = Object.create(null);
|
|
131
|
+
expanded.forEach(([match, replaceWith]) => addToTrie(trieRoot, match, replaceWith));
|
|
132
|
+
return trieRoot;
|
|
133
|
+
}
|
|
134
|
+
function addToTrie(node, match, replaceWith) {
|
|
135
|
+
while (match) {
|
|
136
|
+
const children = node.children || (node.children = Object.create(null));
|
|
137
|
+
const k = match[0];
|
|
138
|
+
const childNode = children[k] || (children[k] = Object.create(null));
|
|
139
|
+
node = childNode;
|
|
140
|
+
match = match.slice(1);
|
|
141
|
+
}
|
|
142
|
+
const s = new Set(node.rep || []);
|
|
143
|
+
s.add(replaceWith);
|
|
144
|
+
node.rep = [...s];
|
|
145
|
+
}
|
|
146
|
+
export const __testing__ = {
|
|
147
|
+
charsetToRepMap: charsetToRepMapRegEx,
|
|
148
|
+
createMapperRegExp,
|
|
149
|
+
createTrie,
|
|
150
|
+
calcAllEdits,
|
|
151
|
+
applyEdits,
|
|
152
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare class SimpleWeakCache<K extends object, T> {
|
|
2
|
+
readonly size: number;
|
|
3
|
+
private L0;
|
|
4
|
+
private L1;
|
|
5
|
+
private L2;
|
|
6
|
+
private sizeL0;
|
|
7
|
+
constructor(size: number);
|
|
8
|
+
has(key: K): boolean;
|
|
9
|
+
get(key: K): T | undefined;
|
|
10
|
+
set(key: K, value: T): void;
|
|
11
|
+
private _set;
|
|
12
|
+
private caches;
|
|
13
|
+
private rotate;
|
|
14
|
+
}
|
|
15
|
+
export declare class AutoWeakCache<K extends object, T> extends SimpleWeakCache<K, T> {
|
|
16
|
+
readonly factory: (key: K) => T;
|
|
17
|
+
constructor(factory: (key: K) => T, size: number);
|
|
18
|
+
get(key: K): T;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* This will cache between `size` and 3 x `size` items.
|
|
22
|
+
* It has three stashes, L0, L1, and L2. Each can contain `size` items.
|
|
23
|
+
* When L0 is full, its items are given to L1 and L1's are given to L2, and L2 is empties.
|
|
24
|
+
*
|
|
25
|
+
* The stashes are searched in order, L0...L2. If an item is found in L1, or L2, it is
|
|
26
|
+
* promoted to L0.
|
|
27
|
+
*/
|
|
28
|
+
export declare class SimpleCache<K, T> {
|
|
29
|
+
readonly size: number;
|
|
30
|
+
private L0;
|
|
31
|
+
private L1;
|
|
32
|
+
private L2;
|
|
33
|
+
constructor(size: number);
|
|
34
|
+
has(key: K): boolean;
|
|
35
|
+
get(key: K): T | undefined;
|
|
36
|
+
set(key: K, value: T): void;
|
|
37
|
+
private _set;
|
|
38
|
+
private caches;
|
|
39
|
+
private rotate;
|
|
40
|
+
}
|
|
41
|
+
export declare class AutoCache<K, T> extends SimpleCache<K, T> {
|
|
42
|
+
readonly factory: (key: K) => T;
|
|
43
|
+
constructor(factory: (key: K) => T, size: number);
|
|
44
|
+
get(key: K): T;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=simpleCache.d.mts.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
export class SimpleWeakCache {
|
|
2
|
+
constructor(size) {
|
|
3
|
+
this.size = size;
|
|
4
|
+
this.L0 = new WeakMap();
|
|
5
|
+
this.L1 = new WeakMap();
|
|
6
|
+
this.L2 = new WeakMap();
|
|
7
|
+
this.sizeL0 = 0;
|
|
8
|
+
}
|
|
9
|
+
has(key) {
|
|
10
|
+
for (const c of this.caches()) {
|
|
11
|
+
if (c.has(key))
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
get(key) {
|
|
17
|
+
for (const c of this.caches()) {
|
|
18
|
+
const entry = c.get(key);
|
|
19
|
+
if (entry) {
|
|
20
|
+
if (c !== this.L0) {
|
|
21
|
+
this._set(key, entry);
|
|
22
|
+
}
|
|
23
|
+
return entry.v;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
set(key, value) {
|
|
29
|
+
this._set(key, { v: value });
|
|
30
|
+
}
|
|
31
|
+
_set(key, entry) {
|
|
32
|
+
if (this.L0.has(key)) {
|
|
33
|
+
this.L0.set(key, entry);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
if (this.sizeL0 >= this.size) {
|
|
37
|
+
this.rotate();
|
|
38
|
+
}
|
|
39
|
+
this.sizeL0 += 1;
|
|
40
|
+
this.L0.set(key, entry);
|
|
41
|
+
}
|
|
42
|
+
caches() {
|
|
43
|
+
return [this.L0, this.L1, this.L2];
|
|
44
|
+
}
|
|
45
|
+
rotate() {
|
|
46
|
+
this.L2 = this.L1;
|
|
47
|
+
this.L1 = this.L0;
|
|
48
|
+
this.L0 = new WeakMap();
|
|
49
|
+
this.sizeL0 = 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class AutoWeakCache extends SimpleWeakCache {
|
|
53
|
+
constructor(factory, size) {
|
|
54
|
+
super(size);
|
|
55
|
+
this.factory = factory;
|
|
56
|
+
}
|
|
57
|
+
get(key) {
|
|
58
|
+
const v = super.get(key);
|
|
59
|
+
if (v !== undefined)
|
|
60
|
+
return v;
|
|
61
|
+
const val = this.factory(key);
|
|
62
|
+
this.set(key, val);
|
|
63
|
+
return val;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* This will cache between `size` and 3 x `size` items.
|
|
68
|
+
* It has three stashes, L0, L1, and L2. Each can contain `size` items.
|
|
69
|
+
* When L0 is full, its items are given to L1 and L1's are given to L2, and L2 is empties.
|
|
70
|
+
*
|
|
71
|
+
* The stashes are searched in order, L0...L2. If an item is found in L1, or L2, it is
|
|
72
|
+
* promoted to L0.
|
|
73
|
+
*/
|
|
74
|
+
export class SimpleCache {
|
|
75
|
+
constructor(size) {
|
|
76
|
+
this.size = size;
|
|
77
|
+
this.L0 = new Map();
|
|
78
|
+
this.L1 = new Map();
|
|
79
|
+
this.L2 = new Map();
|
|
80
|
+
}
|
|
81
|
+
has(key) {
|
|
82
|
+
for (const c of this.caches()) {
|
|
83
|
+
if (c.has(key))
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
get(key) {
|
|
89
|
+
for (const c of this.caches()) {
|
|
90
|
+
const entry = c.get(key);
|
|
91
|
+
if (entry) {
|
|
92
|
+
if (c !== this.L0) {
|
|
93
|
+
this._set(key, entry);
|
|
94
|
+
}
|
|
95
|
+
return entry.v;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
set(key, value) {
|
|
101
|
+
this._set(key, { v: value });
|
|
102
|
+
}
|
|
103
|
+
_set(key, entry) {
|
|
104
|
+
if (this.L0.has(key)) {
|
|
105
|
+
this.L0.set(key, entry);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
if (this.L0.size >= this.size) {
|
|
109
|
+
this.rotate();
|
|
110
|
+
}
|
|
111
|
+
this.L0.set(key, entry);
|
|
112
|
+
}
|
|
113
|
+
caches() {
|
|
114
|
+
return [this.L0, this.L1, this.L2];
|
|
115
|
+
}
|
|
116
|
+
rotate() {
|
|
117
|
+
this.L2 = this.L1;
|
|
118
|
+
this.L1 = this.L0;
|
|
119
|
+
this.L0 = new Map();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export class AutoCache extends SimpleCache {
|
|
123
|
+
constructor(factory, size) {
|
|
124
|
+
super(size);
|
|
125
|
+
this.factory = factory;
|
|
126
|
+
}
|
|
127
|
+
get(key) {
|
|
128
|
+
const v = super.get(key);
|
|
129
|
+
if (v !== undefined)
|
|
130
|
+
return v;
|
|
131
|
+
const val = this.factory(key);
|
|
132
|
+
this.set(key, val);
|
|
133
|
+
return val;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function isUpperCase(word: string): boolean;
|
|
2
|
+
export declare function isLowerCase(word: string): boolean;
|
|
3
|
+
export declare function isFirstCharacterUpper(word: string): boolean;
|
|
4
|
+
export declare function isFirstCharacterLower(word: string): boolean;
|
|
5
|
+
export declare function ucFirst(word: string): string;
|
|
6
|
+
export declare function lcFirst(word: string): string;
|
|
7
|
+
export declare function matchCase(example: string, word: string): string;
|
|
8
|
+
export declare function removeAccents(text: string): string;
|
|
9
|
+
export declare function removeUnboundAccents(text: string): string;
|
|
10
|
+
//# sourceMappingURL=text.d.mts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const regExFirstUpper = /^\p{Lu}\p{M}?\p{Ll}+$/u;
|
|
2
|
+
const regExAllUpper = /^(?:\p{Lu}\p{M}?)+$/u;
|
|
3
|
+
const regExAllLower = /^(?:\p{Ll}\p{M}?)+$/u;
|
|
4
|
+
const regExAccents = /\p{M}/gu;
|
|
5
|
+
export function isUpperCase(word) {
|
|
6
|
+
return !!word.match(regExAllUpper);
|
|
7
|
+
}
|
|
8
|
+
export function isLowerCase(word) {
|
|
9
|
+
return !!word.match(regExAllLower);
|
|
10
|
+
}
|
|
11
|
+
export function isFirstCharacterUpper(word) {
|
|
12
|
+
return isUpperCase(word.slice(0, 1));
|
|
13
|
+
}
|
|
14
|
+
export function isFirstCharacterLower(word) {
|
|
15
|
+
return isLowerCase(word.slice(0, 1));
|
|
16
|
+
}
|
|
17
|
+
export function ucFirst(word) {
|
|
18
|
+
return word.slice(0, 1).toUpperCase() + word.slice(1);
|
|
19
|
+
}
|
|
20
|
+
export function lcFirst(word) {
|
|
21
|
+
return word.slice(0, 1).toLowerCase() + word.slice(1);
|
|
22
|
+
}
|
|
23
|
+
export function matchCase(example, word) {
|
|
24
|
+
if (example.match(regExFirstUpper)) {
|
|
25
|
+
return word.slice(0, 1).toUpperCase() + word.slice(1).toLowerCase();
|
|
26
|
+
}
|
|
27
|
+
if (example.match(regExAllLower)) {
|
|
28
|
+
return word.toLowerCase();
|
|
29
|
+
}
|
|
30
|
+
if (example.match(regExAllUpper)) {
|
|
31
|
+
return word.toUpperCase();
|
|
32
|
+
}
|
|
33
|
+
if (isFirstCharacterUpper(example)) {
|
|
34
|
+
return ucFirst(word);
|
|
35
|
+
}
|
|
36
|
+
if (isFirstCharacterLower(example)) {
|
|
37
|
+
return lcFirst(word);
|
|
38
|
+
}
|
|
39
|
+
return word;
|
|
40
|
+
}
|
|
41
|
+
export function removeAccents(text) {
|
|
42
|
+
return text.normalize('NFD').replace(regExAccents, '');
|
|
43
|
+
}
|
|
44
|
+
export function removeUnboundAccents(text) {
|
|
45
|
+
return text.replace(regExAccents, '');
|
|
46
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { removeAccents } from './text.mjs';
|
|
2
|
+
export function* mapperNormalizeNFC(words) {
|
|
3
|
+
for (const word of words) {
|
|
4
|
+
yield word.normalize('NFC');
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export function* mapperRemoveCaseAndAccents(words) {
|
|
8
|
+
for (const word of words) {
|
|
9
|
+
const lc = word.toLowerCase();
|
|
10
|
+
yield lc;
|
|
11
|
+
const woAccents = removeAccents(lc);
|
|
12
|
+
if (lc !== woAccents)
|
|
13
|
+
yield woAccents;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,25 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-dictionary",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.29.0",
|
|
4
4
|
"description": "A spelling dictionary library useful for checking words and getting suggestions.",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "dist/cjs/index.js",
|
|
7
|
+
"types": "dist/cjs/index.d.ts",
|
|
8
|
+
"module": "dist/esm/index.mjs",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/esm/index.mjs",
|
|
12
|
+
"require": "./dist/cjs/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
7
15
|
"files": [
|
|
8
16
|
"dist",
|
|
17
|
+
"!dist/esm/**/*.js",
|
|
18
|
+
"!dist/esm/**/*.ts",
|
|
19
|
+
"!**/*.tsbuildInfo",
|
|
9
20
|
"!**/__mocks__",
|
|
21
|
+
"!**/test/**",
|
|
10
22
|
"!**/*.test.*",
|
|
11
23
|
"!**/*.spec.*",
|
|
12
24
|
"!**/*.map"
|
|
13
25
|
],
|
|
14
26
|
"scripts": {
|
|
15
|
-
"
|
|
16
|
-
"build
|
|
17
|
-
"
|
|
18
|
-
"clean": "shx rm -rf dist temp coverage .tsbuildinfo",
|
|
27
|
+
"clean": "shx rm -rf dist coverage .tsbuildinfo",
|
|
28
|
+
"build": "tsc -b . && ts2mjs dist/esm",
|
|
29
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
19
30
|
"clean-build": "pnpm run clean && pnpm run build",
|
|
20
|
-
"coverage": "
|
|
21
|
-
"
|
|
22
|
-
"
|
|
31
|
+
"coverage": "pnpm coverage:vitest && pnpm coverage:fix",
|
|
32
|
+
"coverage:vitest": "vitest run --coverage",
|
|
33
|
+
"coverage:fix": "nyc report --temp-dir \"$(pwd)/coverage\" --reporter lcov --report-dir \"$(pwd)/coverage\" --cwd ../..",
|
|
34
|
+
"test:watch": "vitest",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"watch": "tsc -b . -w"
|
|
23
37
|
},
|
|
24
38
|
"repository": {
|
|
25
39
|
"type": "git",
|
|
@@ -37,17 +51,12 @@
|
|
|
37
51
|
"engines": {
|
|
38
52
|
"node": ">=14"
|
|
39
53
|
},
|
|
40
|
-
"devDependencies": {
|
|
41
|
-
"@types/jest": "^29.4.0",
|
|
42
|
-
"jest": "^29.4.3",
|
|
43
|
-
"ts-jest": "^29.0.5"
|
|
44
|
-
},
|
|
45
54
|
"dependencies": {
|
|
46
|
-
"@cspell/cspell-pipe": "6.
|
|
47
|
-
"@cspell/cspell-types": "6.
|
|
48
|
-
"cspell-trie-lib": "6.
|
|
55
|
+
"@cspell/cspell-pipe": "6.29.0",
|
|
56
|
+
"@cspell/cspell-types": "6.29.0",
|
|
57
|
+
"cspell-trie-lib": "6.29.0",
|
|
49
58
|
"fast-equals": "^4.0.3",
|
|
50
|
-
"gensequence": "^
|
|
59
|
+
"gensequence": "^5.0.2"
|
|
51
60
|
},
|
|
52
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "2eabb1c47c12c2a42eb95d30329be6f544ee2ffc"
|
|
53
62
|
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createInlineSpellingDictionary = void 0;
|
|
4
|
-
const AutoResolve_1 = require("../util/AutoResolve");
|
|
5
|
-
const util_1 = require("../util/util");
|
|
6
|
-
const createSpellingDictionary_1 = require("./createSpellingDictionary");
|
|
7
|
-
const FlagWordsDictionary_1 = require("./FlagWordsDictionary");
|
|
8
|
-
const IgnoreWordsDictionary_1 = require("./IgnoreWordsDictionary");
|
|
9
|
-
const SpellingDictionaryCollection_1 = require("./SpellingDictionaryCollection");
|
|
10
|
-
const SuggestDictionary_1 = require("./SuggestDictionary");
|
|
11
|
-
const cache = (0, AutoResolve_1.createAutoResolveWeakCache)();
|
|
12
|
-
function createInlineSpellingDictionary(inlineDict, source) {
|
|
13
|
-
return cache.get(inlineDict, () => {
|
|
14
|
-
const { words, flagWords, ignoreWords, suggestWords, name } = inlineDict;
|
|
15
|
-
const dictSources = [
|
|
16
|
-
words && (0, createSpellingDictionary_1.createSpellingDictionary)(words, name + '-words', source, inlineDict),
|
|
17
|
-
flagWords && (0, FlagWordsDictionary_1.createFlagWordsDictionary)(flagWords, name + '-flag-words', source),
|
|
18
|
-
ignoreWords && (0, IgnoreWordsDictionary_1.createIgnoreWordsDictionary)(ignoreWords, name + '-ignore-words', source),
|
|
19
|
-
suggestWords && (0, SuggestDictionary_1.createSuggestDictionary)(suggestWords, name + '-suggest', source),
|
|
20
|
-
].filter(util_1.isDefined);
|
|
21
|
-
return (0, SpellingDictionaryCollection_1.createCollection)(dictSources, name, source);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
exports.createInlineSpellingDictionary = createInlineSpellingDictionary;
|
|
25
|
-
//# sourceMappingURL=createInlineSpellingDictionary.js.map
|
package/dist/util/repMap.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { CharacterSet, ReplaceMap } from '@cspell/cspell-types';
|
|
2
|
-
export type ReplaceMapper = (src: string) => string;
|
|
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 {};
|
|
11
|
-
//# sourceMappingURL=repMap.d.ts.map
|
package/dist/util/repMap.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.__testing__ = exports.createMapper = void 0;
|
|
4
|
-
const regexHelper_1 = require("./regexHelper");
|
|
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
|
-
}
|
|
13
|
-
const filteredMap = repMap.filter(([match, _]) => !!match);
|
|
14
|
-
if (!filteredMap.length) {
|
|
15
|
-
return (a) => a;
|
|
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
|
-
}
|
|
41
|
-
const regExStr = filteredMap
|
|
42
|
-
.map(([from, _]) => from)
|
|
43
|
-
// make sure it compiles into a regex
|
|
44
|
-
.map((s) => {
|
|
45
|
-
try {
|
|
46
|
-
// fix up any nested ()
|
|
47
|
-
const r = s.match(/\(/) ? s.replace(/\((?=.*\))/g, '(?:').replace(/\(\?:\?/g, '(?') : s;
|
|
48
|
-
new RegExp(r);
|
|
49
|
-
s = r;
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
return (0, regexHelper_1.escapeRegEx)(s);
|
|
53
|
-
}
|
|
54
|
-
return s;
|
|
55
|
-
})
|
|
56
|
-
.map((s) => `(${s})`)
|
|
57
|
-
.join('|');
|
|
58
|
-
const regEx = new RegExp(regExStr, 'g');
|
|
59
|
-
return regEx;
|
|
60
|
-
}
|
|
61
|
-
exports.__testing__ = {
|
|
62
|
-
charsetToRepMap,
|
|
63
|
-
createMapperRegExp,
|
|
64
|
-
};
|
|
65
|
-
//# sourceMappingURL=repMap.js.map
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|