cspell-dictionary 6.10.0 → 6.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SpellingDictionary/ForbiddenWordsDictionary.d.ts +11 -0
- package/dist/SpellingDictionary/ForbiddenWordsDictionary.js +73 -0
- package/dist/SpellingDictionary/SpellingDictionary.d.ts +16 -2
- package/dist/SpellingDictionary/SpellingDictionaryFromTrie.d.ts +9 -1
- package/dist/SpellingDictionary/SpellingDictionaryFromTrie.js +12 -3
- package/dist/SpellingDictionary/createSpellingDictionary.d.ts +12 -5
- package/dist/SpellingDictionary/createSpellingDictionary.js +13 -28
- package/dist/SpellingDictionary/index.d.ts +3 -1
- package/dist/SpellingDictionary/index.js +5 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/package.json +10 -5
|
@@ -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,73 @@
|
|
|
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 SpellingDictionaryFromTrie_1 = require("./SpellingDictionaryFromTrie");
|
|
6
|
+
const createSpellingDictionary_1 = require("./createSpellingDictionary");
|
|
7
|
+
class ForbiddenWordsDictionary {
|
|
8
|
+
constructor(name, source, wordList) {
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.source = source;
|
|
11
|
+
this.containsNoSuggestWords = false;
|
|
12
|
+
this.options = {};
|
|
13
|
+
this.type = 'forbidden';
|
|
14
|
+
this.isDictionaryCaseSensitive = true;
|
|
15
|
+
const words = (0, cspell_trie_lib_1.parseDictionaryLines)(wordList, { stripCaseAndAccents: false });
|
|
16
|
+
const trie = (0, cspell_trie_lib_1.buildTrieFast)(words);
|
|
17
|
+
this.dict = new SpellingDictionaryFromTrie_1.SpellingDictionaryFromTrie(trie, name, createSpellingDictionary_1.defaultOptions, source);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A Forbidden word list does not "have" valid words.
|
|
21
|
+
* Therefore it always returns false.
|
|
22
|
+
* @param _word - the word
|
|
23
|
+
* @param _options - options
|
|
24
|
+
* @returns always false
|
|
25
|
+
*/
|
|
26
|
+
has(_word, _options) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
/** A more detailed search for a word, might take longer than `has` */
|
|
30
|
+
find(word, options) {
|
|
31
|
+
const r = this.dict.find(word, options);
|
|
32
|
+
if (!r || r.found === false || r.forbidden)
|
|
33
|
+
return undefined;
|
|
34
|
+
return { ...r, forbidden: true };
|
|
35
|
+
}
|
|
36
|
+
isForbidden(word) {
|
|
37
|
+
const r = this.find(word);
|
|
38
|
+
if (!r)
|
|
39
|
+
return false;
|
|
40
|
+
return r.forbidden && r.found !== false;
|
|
41
|
+
}
|
|
42
|
+
isNoSuggestWord(_word, _options) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
suggest() {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
genSuggestions() {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
mapWord(word) {
|
|
52
|
+
return word;
|
|
53
|
+
}
|
|
54
|
+
get size() {
|
|
55
|
+
return this.dict.size;
|
|
56
|
+
}
|
|
57
|
+
getErrors() {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create a dictionary where all words are to be forbidden.
|
|
63
|
+
* @param wordList - list of words
|
|
64
|
+
* @param name
|
|
65
|
+
* @param source
|
|
66
|
+
* @param options
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
function createForbiddenWordsDictionary(wordList, name, source) {
|
|
70
|
+
return new ForbiddenWordsDictionary(name, source, wordList);
|
|
71
|
+
}
|
|
72
|
+
exports.createForbiddenWordsDictionary = createForbiddenWordsDictionary;
|
|
73
|
+
//# sourceMappingURL=ForbiddenWordsDictionary.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 */
|
|
@@ -32,5 +32,13 @@ export declare class SpellingDictionaryFromTrie implements SpellingDictionary {
|
|
|
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;
|
|
36
44
|
//# sourceMappingURL=SpellingDictionaryFromTrie.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createSpellingDictionaryFromTrieFile = exports.SpellingDictionaryFromTrie = void 0;
|
|
4
4
|
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
5
|
const repMap_1 = require("../util/repMap");
|
|
6
6
|
const clean_1 = require("../util/clean");
|
|
@@ -139,10 +139,19 @@ class SpellingDictionaryFromTrie {
|
|
|
139
139
|
}
|
|
140
140
|
exports.SpellingDictionaryFromTrie = SpellingDictionaryFromTrie;
|
|
141
141
|
SpellingDictionaryFromTrie.cachedWordsLimit = 50000;
|
|
142
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Create a dictionary from a trie file.
|
|
144
|
+
* @param data - contents of a trie file.
|
|
145
|
+
* @param name - name of dictionary
|
|
146
|
+
* @param source - filename or uri
|
|
147
|
+
* @param options - options.
|
|
148
|
+
* @returns SpellingDictionary
|
|
149
|
+
*/
|
|
150
|
+
function createSpellingDictionaryFromTrieFile(data, name, source, options) {
|
|
151
|
+
data = typeof data === 'string' ? data.split('\n') : data;
|
|
143
152
|
const trieNode = (0, cspell_trie_lib_1.importTrie)(data);
|
|
144
153
|
const trie = new cspell_trie_lib_1.Trie(trieNode);
|
|
145
154
|
return new SpellingDictionaryFromTrie(trie, name, options, source);
|
|
146
155
|
}
|
|
147
|
-
exports.
|
|
156
|
+
exports.createSpellingDictionaryFromTrieFile = createSpellingDictionaryFromTrieFile;
|
|
148
157
|
//# sourceMappingURL=SpellingDictionaryFromTrie.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,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createSpellingDictionary } from './createSpellingDictionary';
|
|
2
|
+
export { createForbiddenWordsDictionary } from './ForbiddenWordsDictionary';
|
|
2
3
|
export type { FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary';
|
|
3
4
|
export { createCollection } from './SpellingDictionaryCollection';
|
|
5
|
+
export { createSpellingDictionaryFromTrieFile } from './SpellingDictionaryFromTrie';
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createSpellingDictionaryFromTrieFile = exports.createCollection = exports.createForbiddenWordsDictionary = exports.createSpellingDictionary = void 0;
|
|
4
4
|
var createSpellingDictionary_1 = require("./createSpellingDictionary");
|
|
5
|
-
Object.defineProperty(exports, "createForbiddenWordsDictionary", { enumerable: true, get: function () { return createSpellingDictionary_1.createForbiddenWordsDictionary; } });
|
|
6
5
|
Object.defineProperty(exports, "createSpellingDictionary", { enumerable: true, get: function () { return createSpellingDictionary_1.createSpellingDictionary; } });
|
|
6
|
+
var ForbiddenWordsDictionary_1 = require("./ForbiddenWordsDictionary");
|
|
7
|
+
Object.defineProperty(exports, "createForbiddenWordsDictionary", { enumerable: true, get: function () { return ForbiddenWordsDictionary_1.createForbiddenWordsDictionary; } });
|
|
7
8
|
var SpellingDictionaryCollection_1 = require("./SpellingDictionaryCollection");
|
|
8
9
|
Object.defineProperty(exports, "createCollection", { enumerable: true, get: function () { return SpellingDictionaryCollection_1.createCollection; } });
|
|
10
|
+
var SpellingDictionaryFromTrie_1 = require("./SpellingDictionaryFromTrie");
|
|
11
|
+
Object.defineProperty(exports, "createSpellingDictionaryFromTrieFile", { enumerable: true, get: function () { return SpellingDictionaryFromTrie_1.createSpellingDictionaryFromTrieFile; } });
|
|
9
12
|
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createCollection, createForbiddenWordsDictionary, createSpellingDictionary } from './SpellingDictionary';
|
|
1
|
+
export { createCollection, createForbiddenWordsDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, } from './SpellingDictionary';
|
|
2
2
|
export type { 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,9 @@
|
|
|
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.createForbiddenWordsDictionary = exports.createCollection = void 0;
|
|
4
4
|
var SpellingDictionary_1 = require("./SpellingDictionary");
|
|
5
5
|
Object.defineProperty(exports, "createCollection", { enumerable: true, get: function () { return SpellingDictionary_1.createCollection; } });
|
|
6
6
|
Object.defineProperty(exports, "createForbiddenWordsDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createForbiddenWordsDictionary; } });
|
|
7
7
|
Object.defineProperty(exports, "createSpellingDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createSpellingDictionary; } });
|
|
8
|
+
Object.defineProperty(exports, "createSpellingDictionaryFromTrieFile", { enumerable: true, get: function () { return SpellingDictionary_1.createSpellingDictionaryFromTrieFile; } });
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-dictionary",
|
|
3
|
-
"version": "6.10.
|
|
3
|
+
"version": "6.10.1",
|
|
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.0.3",
|
|
42
|
+
"jest": "^29.0.3",
|
|
43
|
+
"ts-jest": "^29.0.1"
|
|
44
|
+
},
|
|
40
45
|
"dependencies": {
|
|
41
|
-
"@cspell/cspell-pipe": "^6.10.
|
|
42
|
-
"@cspell/cspell-types": "^6.10.
|
|
43
|
-
"cspell-trie-lib": "^6.10.
|
|
46
|
+
"@cspell/cspell-pipe": "^6.10.1",
|
|
47
|
+
"@cspell/cspell-types": "^6.10.1",
|
|
48
|
+
"cspell-trie-lib": "^6.10.1",
|
|
44
49
|
"fast-equals": "^4.0.3",
|
|
45
50
|
"gensequence": "^4.0.2"
|
|
46
51
|
},
|
|
47
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "03625a3f7ca4ef85f3549ccae73d90d2cd3ac0f0"
|
|
48
53
|
}
|