cspell-dictionary 6.14.2 → 6.15.0

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