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.
Files changed (129) hide show
  1. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/CachingDictionary.d.ts +3 -3
  2. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/CachingDictionary.js +9 -9
  3. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/FlagWordsDictionary.d.ts +1 -1
  4. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/FlagWordsDictionary.js +11 -11
  5. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/IgnoreWordsDictionary.d.ts +1 -1
  6. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/IgnoreWordsDictionary.js +5 -5
  7. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionary.d.ts +7 -0
  8. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryCollection.d.ts +1 -1
  9. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryCollection.js +12 -12
  10. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryFromTrie.d.ts +3 -2
  11. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryFromTrie.js +18 -17
  12. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryMethods.d.ts +1 -1
  13. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionaryMethods.js +5 -5
  14. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SuggestDictionary.d.ts +2 -2
  15. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SuggestDictionary.js +9 -9
  16. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Terms/index.d.ts +1 -1
  17. package/dist/cjs/SpellingDictionary/Typos/index.d.ts +4 -0
  18. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/index.js +7 -7
  19. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/typos.d.ts +1 -1
  20. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/typosParser.d.ts +1 -1
  21. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/typosParser.js +6 -6
  22. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/util.d.ts +1 -1
  23. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/TyposDictionary.d.ts +2 -2
  24. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/TyposDictionary.js +10 -10
  25. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/createInlineSpellingDictionary.d.ts +1 -1
  26. package/dist/cjs/SpellingDictionary/createInlineSpellingDictionary.js +25 -0
  27. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/createSpellingDictionary.d.ts +2 -2
  28. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/createSpellingDictionary.js +9 -9
  29. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/index.d.ts +10 -10
  30. package/dist/{SpellingDictionary → cjs/SpellingDictionary}/index.js +20 -20
  31. package/dist/{index.d.ts → cjs/index.d.ts} +2 -2
  32. package/dist/{index.js → cjs/index.js} +11 -11
  33. package/dist/{util → cjs/util}/clean.d.ts +1 -1
  34. package/dist/cjs/util/repMap.d.ts +27 -0
  35. package/dist/cjs/util/repMap.js +158 -0
  36. package/dist/{util → cjs/util}/textMappers.js +2 -2
  37. package/dist/esm/SpellingDictionary/CachingDictionary.d.mts +30 -0
  38. package/dist/esm/SpellingDictionary/CachingDictionary.mjs +45 -0
  39. package/dist/esm/SpellingDictionary/FlagWordsDictionary.d.mts +11 -0
  40. package/dist/esm/SpellingDictionary/FlagWordsDictionary.mjs +134 -0
  41. package/dist/esm/SpellingDictionary/IgnoreWordsDictionary.d.mts +11 -0
  42. package/dist/esm/SpellingDictionary/IgnoreWordsDictionary.mjs +96 -0
  43. package/dist/esm/SpellingDictionary/SpellingDictionary.d.mts +150 -0
  44. package/dist/esm/SpellingDictionary/SpellingDictionary.mjs +4 -0
  45. package/dist/esm/SpellingDictionary/SpellingDictionaryCollection.d.mts +16 -0
  46. package/dist/esm/SpellingDictionary/SpellingDictionaryCollection.mjs +111 -0
  47. package/dist/esm/SpellingDictionary/SpellingDictionaryFromTrie.d.mts +50 -0
  48. package/dist/esm/SpellingDictionary/SpellingDictionaryFromTrie.mjs +172 -0
  49. package/dist/esm/SpellingDictionary/SpellingDictionaryMethods.d.mts +26 -0
  50. package/dist/esm/SpellingDictionary/SpellingDictionaryMethods.mjs +96 -0
  51. package/dist/esm/SpellingDictionary/SuggestDictionary.d.mts +20 -0
  52. package/dist/esm/SpellingDictionary/SuggestDictionary.mjs +97 -0
  53. package/dist/esm/SpellingDictionary/Terms/index.d.mts +2 -0
  54. package/dist/esm/SpellingDictionary/Terms/index.mjs +1 -0
  55. package/dist/esm/SpellingDictionary/Terms/terms.d.mts +12 -0
  56. package/dist/esm/SpellingDictionary/Terms/terms.mjs +1 -0
  57. package/dist/esm/SpellingDictionary/Typos/index.d.mts +4 -0
  58. package/dist/esm/SpellingDictionary/Typos/index.mjs +2 -0
  59. package/dist/esm/SpellingDictionary/Typos/typos.d.mts +18 -0
  60. package/dist/esm/SpellingDictionary/Typos/typos.mjs +1 -0
  61. package/dist/esm/SpellingDictionary/Typos/typosParser.d.mts +34 -0
  62. package/dist/esm/SpellingDictionary/Typos/typosParser.mjs +131 -0
  63. package/dist/esm/SpellingDictionary/Typos/util.d.mts +31 -0
  64. package/dist/esm/SpellingDictionary/Typos/util.mjs +105 -0
  65. package/dist/esm/SpellingDictionary/TyposDictionary.d.mts +21 -0
  66. package/dist/esm/SpellingDictionary/TyposDictionary.mjs +129 -0
  67. package/dist/esm/SpellingDictionary/createInlineSpellingDictionary.d.mts +3 -0
  68. package/dist/esm/SpellingDictionary/createInlineSpellingDictionary.mjs +20 -0
  69. package/dist/esm/SpellingDictionary/createSpellingDictionary.d.mts +23 -0
  70. package/dist/esm/SpellingDictionary/createSpellingDictionary.mjs +68 -0
  71. package/dist/esm/SpellingDictionary/defaults.d.mts +3 -0
  72. package/dist/esm/SpellingDictionary/defaults.mjs +2 -0
  73. package/dist/esm/SpellingDictionary/index.d.mts +11 -0
  74. package/dist/esm/SpellingDictionary/index.mjs +9 -0
  75. package/dist/esm/index.d.mts +3 -0
  76. package/dist/esm/index.mjs +1 -0
  77. package/dist/esm/util/AutoCache.d.mts +25 -0
  78. package/dist/esm/util/AutoCache.mjs +67 -0
  79. package/dist/esm/util/AutoResolve.d.mts +21 -0
  80. package/dist/esm/util/AutoResolve.mjs +52 -0
  81. package/dist/esm/util/IterableLike.d.mts +4 -0
  82. package/dist/esm/util/IterableLike.mjs +1 -0
  83. package/dist/esm/util/clean.d.mts +7 -0
  84. package/dist/esm/util/clean.mjs +13 -0
  85. package/dist/esm/util/regexHelper.d.mts +7 -0
  86. package/dist/esm/util/regexHelper.mjs +8 -0
  87. package/dist/esm/util/repMap.d.mts +27 -0
  88. package/dist/esm/util/repMap.mjs +152 -0
  89. package/dist/esm/util/simpleCache.d.mts +46 -0
  90. package/dist/esm/util/simpleCache.mjs +135 -0
  91. package/dist/esm/util/text.d.mts +10 -0
  92. package/dist/esm/util/text.mjs +46 -0
  93. package/dist/esm/util/textMappers.d.mts +3 -0
  94. package/dist/esm/util/textMappers.mjs +15 -0
  95. package/dist/esm/util/types.d.mts +7 -0
  96. package/dist/esm/util/types.mjs +1 -0
  97. package/dist/esm/util/util.d.mts +2 -0
  98. package/dist/esm/util/util.mjs +3 -0
  99. package/package.json +29 -20
  100. package/dist/SpellingDictionary/Typos/index.d.ts +0 -4
  101. package/dist/SpellingDictionary/createInlineSpellingDictionary.js +0 -25
  102. package/dist/util/repMap.d.ts +0 -11
  103. package/dist/util/repMap.js +0 -65
  104. /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/SpellingDictionary.js +0 -0
  105. /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Terms/index.js +0 -0
  106. /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Terms/terms.d.ts +0 -0
  107. /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Terms/terms.js +0 -0
  108. /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/typos.js +0 -0
  109. /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/Typos/util.js +0 -0
  110. /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/defaults.d.ts +0 -0
  111. /package/dist/{SpellingDictionary → cjs/SpellingDictionary}/defaults.js +0 -0
  112. /package/dist/{util → cjs/util}/AutoCache.d.ts +0 -0
  113. /package/dist/{util → cjs/util}/AutoCache.js +0 -0
  114. /package/dist/{util → cjs/util}/AutoResolve.d.ts +0 -0
  115. /package/dist/{util → cjs/util}/AutoResolve.js +0 -0
  116. /package/dist/{util → cjs/util}/IterableLike.d.ts +0 -0
  117. /package/dist/{util → cjs/util}/IterableLike.js +0 -0
  118. /package/dist/{util → cjs/util}/clean.js +0 -0
  119. /package/dist/{util → cjs/util}/regexHelper.d.ts +0 -0
  120. /package/dist/{util → cjs/util}/regexHelper.js +0 -0
  121. /package/dist/{util → cjs/util}/simpleCache.d.ts +0 -0
  122. /package/dist/{util → cjs/util}/simpleCache.js +0 -0
  123. /package/dist/{util → cjs/util}/text.d.ts +0 -0
  124. /package/dist/{util → cjs/util}/text.js +0 -0
  125. /package/dist/{util → cjs/util}/textMappers.d.ts +0 -0
  126. /package/dist/{util → cjs/util}/types.d.ts +0 -0
  127. /package/dist/{util → cjs/util}/types.js +0 -0
  128. /package/dist/{util → cjs/util}/util.d.ts +0 -0
  129. /package/dist/{util → cjs/util}/util.js +0 -0
@@ -0,0 +1,105 @@
1
+ import { opConcatMap, opFilter, pipe } from '@cspell/cspell-pipe/sync';
2
+ function normalizeTyposDefValue(value) {
3
+ if (!value)
4
+ return false;
5
+ if (typeof value === 'string')
6
+ return value;
7
+ const unique = [...new Set(value)];
8
+ return unique.length > 1 ? unique : unique.length === 1 ? unique[0] : false;
9
+ }
10
+ export function mergeDefEntry(targetDef, key, value) {
11
+ const curValue = targetDef[key];
12
+ if (!curValue) {
13
+ targetDef[key] = normalizeTyposDefValue(value);
14
+ return targetDef;
15
+ }
16
+ if (!value)
17
+ return targetDef;
18
+ const newValue = Array.isArray(curValue) ? curValue : [curValue];
19
+ if (Array.isArray(value)) {
20
+ newValue.push(...value);
21
+ }
22
+ else {
23
+ newValue.push(value);
24
+ }
25
+ targetDef[key] = normalizeTyposDefValue(newValue);
26
+ return targetDef;
27
+ }
28
+ /**
29
+ * Merge in place the entries `fromDef` into `targetDef`
30
+ * @param targetDef - the target
31
+ * @param fromDef - the source
32
+ * @returns the target
33
+ */
34
+ export function mergeDef(targetDef, fromDef) {
35
+ for (const key of Object.keys(fromDef)) {
36
+ mergeDefEntry(targetDef, key, fromDef[key]);
37
+ }
38
+ return targetDef;
39
+ }
40
+ /**
41
+ * Append an entry to a TyposDef.
42
+ * @param def - modified in place
43
+ * @param entry- entry to add.
44
+ * @returns def
45
+ */
46
+ export function appendToDef(def, entry) {
47
+ if (!entry)
48
+ return def;
49
+ if (typeof entry === 'string') {
50
+ if (!def[entry]) {
51
+ def[entry] = false;
52
+ }
53
+ return def;
54
+ }
55
+ if (Array.isArray(entry)) {
56
+ const [key, ...sugs] = entry.map((s) => s.trim());
57
+ if (!key)
58
+ return def;
59
+ const s = sugs.map((s) => s.trim()).filter((s) => !!s);
60
+ return mergeDefEntry(def, key, s);
61
+ }
62
+ return mergeDef(def, entry);
63
+ }
64
+ export function createTyposDef(entries) {
65
+ const def = Object.create(null);
66
+ if (!entries)
67
+ return def;
68
+ for (const [key, value] of entries) {
69
+ def[key] = isDefined(value) ? value : false;
70
+ }
71
+ return def;
72
+ }
73
+ /**
74
+ * Extract all suggestions.
75
+ * @param typosDef - the def
76
+ * @returns the set of suggestions.
77
+ */
78
+ export function extractAllSuggestions(typosDef) {
79
+ const allSugs = pipe(Object.values(typosDef), opFilter(hasSuggestions), opConcatMap((v) => (Array.isArray(v) ? v : [v])));
80
+ return new Set(allSugs);
81
+ }
82
+ /**
83
+ * Extract all words that have been explicitly ignore because they contains the `ignorePrefix`.
84
+ * @param typosDef - the def
85
+ * @param ignorePrefix - prefix
86
+ * @returns set of ignored words with the prefix removed.
87
+ */
88
+ export function extractIgnoreValues(typosDef, ignorePrefix) {
89
+ const pfxLen = ignorePrefix.length;
90
+ return new Set(Object.keys(typosDef)
91
+ .filter((k) => k.startsWith(ignorePrefix))
92
+ .map((k) => k.slice(pfxLen)));
93
+ }
94
+ function isDefined(v) {
95
+ return v !== undefined && v !== null;
96
+ }
97
+ function isString(v) {
98
+ return typeof v === 'string';
99
+ }
100
+ function isArray(v) {
101
+ return Array.isArray(v);
102
+ }
103
+ function hasSuggestions(v) {
104
+ return isString(v) || isArray(v);
105
+ }
@@ -0,0 +1,21 @@
1
+ import type { IgnoreCaseOption, SpellingDictionary } from './SpellingDictionary.mjs';
2
+ import { type TypoEntry, type TyposDef } from './Typos/index.mjs';
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.mts.map
@@ -0,0 +1,129 @@
1
+ import { opAppend, pipe } from '@cspell/cspell-pipe/sync';
2
+ import { createAutoResolveWeakCache } from '../util/AutoResolve.mjs';
3
+ import { mapperRemoveCaseAndAccents } from '../util/textMappers.mjs';
4
+ import * as defaults from './defaults.mjs';
5
+ import { processEntriesToTyposDef } from './Typos/index.mjs';
6
+ import { extractAllSuggestions, extractIgnoreValues } from './Typos/util.mjs';
7
+ class TyposDictionaryImpl {
8
+ constructor(name, source, typosDef, ignoreList) {
9
+ this.name = name;
10
+ this.source = source;
11
+ this.typosDef = typosDef;
12
+ this.options = {};
13
+ this.type = 'typos';
14
+ this.isDictionaryCaseSensitive = true;
15
+ this.size = Object.keys(typosDef).length;
16
+ this.explicitIgnoreWords = extractIgnoreValues(typosDef, '!');
17
+ this.suggestions = extractAllSuggestions(typosDef);
18
+ this.ignoreWords = new Set(pipe(this.explicitIgnoreWords, opAppend(ignoreList || [])));
19
+ this.suggestionsLower = new Set(pipe(this.suggestions, mapperRemoveCaseAndAccents));
20
+ this.containsNoSuggestWords = this.ignoreWords.size > 0;
21
+ }
22
+ /**
23
+ * A Forbidden word list does not "have" valid words.
24
+ * Therefore it always returns false.
25
+ * @param _word - the word
26
+ * @param _options - options
27
+ * @returns always false
28
+ */
29
+ has(_word, _options) {
30
+ return false;
31
+ }
32
+ /** A more detailed search for a word, might take longer than `has` */
33
+ find(word, options) {
34
+ const result = this._findForms(word, options?.ignoreCase ?? defaults.ignoreCase);
35
+ if (result === false)
36
+ return undefined;
37
+ const { found, ignore } = result;
38
+ return { found, forbidden: !ignore, noSuggest: ignore };
39
+ }
40
+ _findForms(word, ignoreCaseAndAccents) {
41
+ const lcWord = word.toLowerCase();
42
+ if (this.ignoreWords.has(word)) {
43
+ return { found: word, ignore: true };
44
+ }
45
+ if (this.suggestions.has(word)) {
46
+ return false;
47
+ }
48
+ if (ignoreCaseAndAccents) {
49
+ if (this.suggestionsLower.has(lcWord)) {
50
+ return false;
51
+ }
52
+ if (this.ignoreWords.has(lcWord)) {
53
+ return { found: lcWord, ignore: true };
54
+ }
55
+ }
56
+ if (word in this.typosDef)
57
+ return { found: word, ignore: false };
58
+ if (lcWord in this.typosDef)
59
+ return { found: lcWord, ignore: false };
60
+ return false;
61
+ }
62
+ isForbidden(word, ignoreCaseAndAccents = defaults.isForbiddenIgnoreCaseAndAccents) {
63
+ const found = this._findForms(word, ignoreCaseAndAccents);
64
+ return found !== false && !found.ignore;
65
+ }
66
+ isNoSuggestWord(word, options) {
67
+ const result = this.find(word, options);
68
+ return result?.noSuggest ?? false;
69
+ }
70
+ /**
71
+ * Determine if the word can appear in a list of suggestions.
72
+ * @param word - word
73
+ * @param ignoreCaseAndAccents - ignore case.
74
+ * @returns true if a word is suggested, otherwise false.
75
+ */
76
+ isSuggestedWord(word, ignoreCaseAndAccents = defaults.isForbiddenIgnoreCaseAndAccents) {
77
+ if (this.suggestions.has(word))
78
+ return true;
79
+ const lcWord = word.toLowerCase();
80
+ return ignoreCaseAndAccents && (this.suggestions.has(lcWord) || this.suggestionsLower.has(lcWord));
81
+ }
82
+ suggest(word) {
83
+ return this._suggest(word) || this._suggest(word.toLowerCase()) || [];
84
+ }
85
+ _suggest(word) {
86
+ if (this.ignoreWords.has(word))
87
+ return [];
88
+ if (!(word in this.typosDef))
89
+ return undefined;
90
+ const sug = this.typosDef[word];
91
+ const isPreferred = true;
92
+ if (!sug)
93
+ return [];
94
+ if (typeof sug === 'string') {
95
+ return [
96
+ {
97
+ word: sug,
98
+ cost: 1,
99
+ isPreferred,
100
+ },
101
+ ];
102
+ }
103
+ return sug.map((word, index) => ({ word, cost: index + 1, isPreferred }));
104
+ }
105
+ genSuggestions(collector) {
106
+ const sugs = this.suggest(collector.word);
107
+ sugs.forEach((result) => collector.add(result));
108
+ }
109
+ mapWord(word) {
110
+ return word;
111
+ }
112
+ getErrors() {
113
+ return [];
114
+ }
115
+ }
116
+ const createCache = createAutoResolveWeakCache();
117
+ /**
118
+ * Create a dictionary where all words are to be forbidden.
119
+ * @param entries - list of Typos Entries
120
+ * @param name - name of dictionary
121
+ * @param source - source
122
+ * @returns
123
+ */
124
+ export function createTyposDictionary(entries, name, source) {
125
+ return createCache.get(entries, () => {
126
+ const def = processEntriesToTyposDef(entries);
127
+ return new TyposDictionaryImpl(name, source, def);
128
+ });
129
+ }
@@ -0,0 +1,3 @@
1
+ import type { DictionaryDefinitionInline, SpellingDictionary } from './SpellingDictionary.mjs';
2
+ export declare function createInlineSpellingDictionary(inlineDict: DictionaryDefinitionInline, source: string): SpellingDictionary;
3
+ //# sourceMappingURL=createInlineSpellingDictionary.d.mts.map
@@ -0,0 +1,20 @@
1
+ import { createAutoResolveWeakCache } from '../util/AutoResolve.mjs';
2
+ import { isDefined } from '../util/util.mjs';
3
+ import { createSpellingDictionary } from './createSpellingDictionary.mjs';
4
+ import { createFlagWordsDictionary } from './FlagWordsDictionary.mjs';
5
+ import { createIgnoreWordsDictionary } from './IgnoreWordsDictionary.mjs';
6
+ import { createCollection } from './SpellingDictionaryCollection.mjs';
7
+ import { createSuggestDictionary } from './SuggestDictionary.mjs';
8
+ const cache = createAutoResolveWeakCache();
9
+ export function createInlineSpellingDictionary(inlineDict, source) {
10
+ return cache.get(inlineDict, () => {
11
+ const { words, flagWords, ignoreWords, suggestWords, name } = inlineDict;
12
+ const dictSources = [
13
+ words && createSpellingDictionary(words, name + '-words', source, inlineDict),
14
+ flagWords && createFlagWordsDictionary(flagWords, name + '-flag-words', source),
15
+ ignoreWords && createIgnoreWordsDictionary(ignoreWords, name + '-ignore-words', source),
16
+ suggestWords && createSuggestDictionary(suggestWords, name + '-suggest', source),
17
+ ].filter(isDefined);
18
+ return createCollection(dictSources, name, source);
19
+ });
20
+ }
@@ -0,0 +1,23 @@
1
+ import type { IterableLike } from '../util/IterableLike.mjs';
2
+ import type { DictionaryInfo, SpellingDictionary, SpellingDictionaryOptions } from './SpellingDictionary.mjs';
3
+ /**
4
+ * Create a SpellingDictionary
5
+ * @param wordList - list of words
6
+ * @param name - name of dictionary
7
+ * @param source - filename or uri
8
+ * @param options - dictionary options
9
+ * @returns a Spelling Dictionary
10
+ */
11
+ export declare function createSpellingDictionary(wordList: readonly string[] | IterableLike<string>, name: string, source: string, options?: SpellingDictionaryOptions | undefined): SpellingDictionary;
12
+ export interface SpellingDictionaryLoadError extends Error {
13
+ /** The Error Name */
14
+ readonly name: string;
15
+ /** Possible Cause */
16
+ readonly cause?: Error | undefined;
17
+ /** Message to Display */
18
+ readonly message: string;
19
+ /** Dictionary Information */
20
+ readonly info: DictionaryInfo;
21
+ }
22
+ export declare function createFailedToLoadDictionary(name: string, source: string, error: Error, options?: SpellingDictionaryOptions | undefined): SpellingDictionary;
23
+ //# sourceMappingURL=createSpellingDictionary.d.mts.map
@@ -0,0 +1,68 @@
1
+ import { buildTrieFast, parseDictionaryLines } from 'cspell-trie-lib';
2
+ import { deepEqual } from 'fast-equals';
3
+ import { AutoWeakCache, SimpleCache } from '../util/simpleCache.mjs';
4
+ import { defaultOptions } from './SpellingDictionary.mjs';
5
+ import { SpellingDictionaryFromTrie } from './SpellingDictionaryFromTrie.mjs';
6
+ import { createWeightMapFromDictionaryInformation } from './SpellingDictionaryMethods.mjs';
7
+ const cachedDictionaries = new AutoWeakCache(_createSpellingDictionary, 64);
8
+ const maxSetSize = 3;
9
+ const cachedParamsByWordList = new SimpleCache(64);
10
+ /**
11
+ * Create a SpellingDictionary
12
+ * @param wordList - list of words
13
+ * @param name - name of dictionary
14
+ * @param source - filename or uri
15
+ * @param options - dictionary options
16
+ * @returns a Spelling Dictionary
17
+ */
18
+ export function createSpellingDictionary(wordList, name, source, options) {
19
+ const params = [wordList, name, source, options];
20
+ if (!Array.isArray(wordList)) {
21
+ return _createSpellingDictionary(params);
22
+ }
23
+ const cached = cachedParamsByWordList.get(name) || new Set();
24
+ for (const cachedParams of cached) {
25
+ if (deepEqual(params, cachedParams)) {
26
+ return cachedDictionaries.get(cachedParams);
27
+ }
28
+ }
29
+ if (cached.size > maxSetSize)
30
+ cached.clear();
31
+ cached.add(params);
32
+ cachedParamsByWordList.set(name, cached);
33
+ return cachedDictionaries.get(params);
34
+ }
35
+ function _createSpellingDictionary(params) {
36
+ const [wordList, name, source, options] = params;
37
+ // console.log(`createSpellingDictionary ${name} ${source}`);
38
+ const parseOptions = { stripCaseAndAccents: options?.supportNonStrictSearches ?? true };
39
+ const words = parseDictionaryLines(wordList, parseOptions);
40
+ const trie = buildTrieFast(words);
41
+ const opts = { ...(options || defaultOptions) };
42
+ if (opts.weightMap === undefined && opts.dictionaryInformation) {
43
+ opts.weightMap = createWeightMapFromDictionaryInformation(opts.dictionaryInformation);
44
+ }
45
+ return new SpellingDictionaryFromTrie(trie, name, opts, source);
46
+ }
47
+ export function createFailedToLoadDictionary(name, source, error, options) {
48
+ options = options || {};
49
+ return {
50
+ name,
51
+ source,
52
+ type: 'error',
53
+ containsNoSuggestWords: false,
54
+ has: () => false,
55
+ find: () => undefined,
56
+ isNoSuggestWord: () => false,
57
+ isForbidden: () => false,
58
+ suggest: () => [],
59
+ mapWord: (a) => a,
60
+ genSuggestions: () => {
61
+ return;
62
+ },
63
+ size: 0,
64
+ options,
65
+ isDictionaryCaseSensitive: false,
66
+ getErrors: () => [error],
67
+ };
68
+ }
@@ -0,0 +1,3 @@
1
+ export declare const ignoreCase: true;
2
+ export declare const isForbiddenIgnoreCaseAndAccents: false;
3
+ //# sourceMappingURL=defaults.d.mts.map
@@ -0,0 +1,2 @@
1
+ export const ignoreCase = true;
2
+ export const isForbiddenIgnoreCaseAndAccents = false;
@@ -0,0 +1,11 @@
1
+ export { CachingDictionary, createCachingDictionary } from './CachingDictionary.mjs';
2
+ export { createInlineSpellingDictionary } from './createInlineSpellingDictionary.mjs';
3
+ export { createFailedToLoadDictionary, createSpellingDictionary } from './createSpellingDictionary.mjs';
4
+ export { createFlagWordsDictionary, createFlagWordsDictionary as createForbiddenWordsDictionary, } from './FlagWordsDictionary.mjs';
5
+ export { createIgnoreWordsDictionary } from './IgnoreWordsDictionary.mjs';
6
+ export type { DictionaryDefinitionInline, FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary.mjs';
7
+ export { createCollection, SpellingDictionaryCollection } from './SpellingDictionaryCollection.mjs';
8
+ export { createSpellingDictionaryFromTrieFile } from './SpellingDictionaryFromTrie.mjs';
9
+ export { createSuggestDictionary } from './SuggestDictionary.mjs';
10
+ export { createTyposDictionary } from './TyposDictionary.mjs';
11
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1,9 @@
1
+ export { createCachingDictionary } from './CachingDictionary.mjs';
2
+ export { createInlineSpellingDictionary } from './createInlineSpellingDictionary.mjs';
3
+ export { createFailedToLoadDictionary, createSpellingDictionary } from './createSpellingDictionary.mjs';
4
+ export { createFlagWordsDictionary, createFlagWordsDictionary as createForbiddenWordsDictionary, } from './FlagWordsDictionary.mjs';
5
+ export { createIgnoreWordsDictionary } from './IgnoreWordsDictionary.mjs';
6
+ export { createCollection } from './SpellingDictionaryCollection.mjs';
7
+ export { createSpellingDictionaryFromTrieFile } from './SpellingDictionaryFromTrie.mjs';
8
+ export { createSuggestDictionary } from './SuggestDictionary.mjs';
9
+ export { createTyposDictionary } from './TyposDictionary.mjs';
@@ -0,0 +1,3 @@
1
+ export type { CachingDictionary, FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryCollection, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary/index.mjs';
2
+ export { createCachingDictionary, createCollection, createFailedToLoadDictionary, createFlagWordsDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createInlineSpellingDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, createSuggestDictionary, } from './SpellingDictionary/index.mjs';
3
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ export { createCachingDictionary, createCollection, createFailedToLoadDictionary, createFlagWordsDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createInlineSpellingDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, createSuggestDictionary, } from './SpellingDictionary/index.mjs';
@@ -0,0 +1,25 @@
1
+ interface AutoCache<R> extends CacheStats {
2
+ (word: string): R;
3
+ }
4
+ export interface CacheStats {
5
+ hits: number;
6
+ misses: number;
7
+ swaps: number;
8
+ }
9
+ declare class Cache01<R> implements CacheStats {
10
+ readonly maxSize: number;
11
+ private count;
12
+ private cache0;
13
+ private cache1;
14
+ hits: number;
15
+ misses: number;
16
+ swaps: number;
17
+ constructor(maxSize: number);
18
+ get(key: string): R | undefined;
19
+ set(key: string, value: R): this;
20
+ }
21
+ export declare function createCache01<R>(size: number): Cache01<R>;
22
+ export declare function autoCache<R>(fn: (p: string) => R, size?: number): AutoCache<R>;
23
+ export declare function extractStats(ac: AutoCache<unknown> | CacheStats): CacheStats;
24
+ export {};
25
+ //# sourceMappingURL=AutoCache.d.mts.map
@@ -0,0 +1,67 @@
1
+ const CACHE_SIZE = 100;
2
+ class Cache01 {
3
+ constructor(maxSize) {
4
+ this.maxSize = maxSize;
5
+ this.count = 0;
6
+ this.cache0 = Object.create(null);
7
+ this.cache1 = Object.create(null);
8
+ this.hits = 0;
9
+ this.misses = 0;
10
+ this.swaps = 0;
11
+ }
12
+ get(key) {
13
+ const cache0 = this.cache0;
14
+ const cache1 = this.cache1;
15
+ if (key in cache0) {
16
+ ++this.hits;
17
+ return cache0[key];
18
+ }
19
+ if (key in cache1) {
20
+ ++this.hits;
21
+ ++this.count;
22
+ const r = cache1[key];
23
+ cache0[key] = r;
24
+ return r;
25
+ }
26
+ ++this.misses;
27
+ return undefined;
28
+ }
29
+ set(key, value) {
30
+ if (this.count >= this.maxSize) {
31
+ this.cache1 = this.cache0;
32
+ this.cache0 = Object.create(null);
33
+ this.swaps++;
34
+ this.count = 0;
35
+ }
36
+ ++this.count;
37
+ this.cache0[key] = value;
38
+ return this;
39
+ }
40
+ }
41
+ export function createCache01(size) {
42
+ return new Cache01(size);
43
+ }
44
+ export function autoCache(fn, size = CACHE_SIZE) {
45
+ const cache = createCache01(size);
46
+ const ac = get;
47
+ ac.hits = 0;
48
+ ac.misses = 0;
49
+ ac.swaps = 0;
50
+ function get(k) {
51
+ const f = cache.get(k);
52
+ if (f !== undefined) {
53
+ ++ac.hits;
54
+ return f;
55
+ }
56
+ const r = fn(k);
57
+ cache.set(k, r);
58
+ ac.swaps = cache.swaps;
59
+ ++ac.misses;
60
+ return r;
61
+ }
62
+ return ac;
63
+ }
64
+ export function extractStats(ac) {
65
+ const { hits, misses, swaps } = ac;
66
+ return { hits, misses, swaps };
67
+ }
@@ -0,0 +1,21 @@
1
+ export declare function autoResolve<K, V>(map: Map<K, V>, key: K, resolve: (k: K) => V): V;
2
+ export declare class AutoResolveCache<K, V> {
3
+ readonly map: Map<K, V>;
4
+ get(k: K): V | undefined;
5
+ get(k: K, resolve: (k: K) => V): V;
6
+ get(k: K, resolve?: (k: K) => V): V | undefined;
7
+ has(k: K): boolean;
8
+ set(k: K, v: V): this;
9
+ }
10
+ export declare function createAutoResolveCache<K, V>(): AutoResolveCache<K, V>;
11
+ export declare function autoResolveWeak<K extends object, V>(map: WeakMap<K, V>, key: K, resolve: (k: K) => V): V;
12
+ export declare class AutoResolveWeakCache<K extends object, V> {
13
+ readonly map: WeakMap<K, V>;
14
+ get(k: K): V | undefined;
15
+ get(k: K, resolve: (k: K) => V): V;
16
+ get(k: K, resolve?: (k: K) => V): V | undefined;
17
+ has(k: K): boolean;
18
+ set(k: K, v: V): this;
19
+ }
20
+ export declare function createAutoResolveWeakCache<K extends object, V>(): AutoResolveWeakCache<K, V>;
21
+ //# sourceMappingURL=AutoResolve.d.mts.map
@@ -0,0 +1,52 @@
1
+ export function autoResolve(map, key, resolve) {
2
+ const found = map.get(key);
3
+ if (found !== undefined || map.has(key))
4
+ return found;
5
+ const value = resolve(key);
6
+ map.set(key, value);
7
+ return value;
8
+ }
9
+ export class AutoResolveCache {
10
+ constructor() {
11
+ this.map = new Map();
12
+ }
13
+ get(k, resolve) {
14
+ return resolve ? autoResolve(this.map, k, resolve) : this.map.get(k);
15
+ }
16
+ has(k) {
17
+ return this.map.has(k);
18
+ }
19
+ set(k, v) {
20
+ this.map.set(k, v);
21
+ return this;
22
+ }
23
+ }
24
+ export function createAutoResolveCache() {
25
+ return new AutoResolveCache();
26
+ }
27
+ export function autoResolveWeak(map, key, resolve) {
28
+ const found = map.get(key);
29
+ if (found !== undefined || map.has(key))
30
+ return found;
31
+ const value = resolve(key);
32
+ map.set(key, value);
33
+ return value;
34
+ }
35
+ export class AutoResolveWeakCache {
36
+ constructor() {
37
+ this.map = new WeakMap();
38
+ }
39
+ get(k, resolve) {
40
+ return resolve ? autoResolveWeak(this.map, k, resolve) : this.map.get(k);
41
+ }
42
+ has(k) {
43
+ return this.map.has(k);
44
+ }
45
+ set(k, v) {
46
+ this.map.set(k, v);
47
+ return this;
48
+ }
49
+ }
50
+ export function createAutoResolveWeakCache() {
51
+ return new AutoResolveWeakCache();
52
+ }
@@ -0,0 +1,4 @@
1
+ export interface IterableLike<T> {
2
+ [Symbol.iterator]: () => Iterator<T> | IterableIterator<T>;
3
+ }
4
+ //# sourceMappingURL=IterableLike.d.mts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { RemoveUndefined } from './types.mjs';
2
+ /**
3
+ * Delete all `undefined` fields from an object.
4
+ * @param src - object to be cleaned
5
+ */
6
+ export declare function clean<T extends object>(src: T): RemoveUndefined<T>;
7
+ //# sourceMappingURL=clean.d.mts.map
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Delete all `undefined` fields from an object.
3
+ * @param src - object to be cleaned
4
+ */
5
+ export function clean(src) {
6
+ const r = src;
7
+ for (const key of Object.keys(r)) {
8
+ if (r[key] === undefined) {
9
+ delete r[key];
10
+ }
11
+ }
12
+ return r;
13
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Escape a string so it can be used as an exact match within a RegExp.
3
+ * @param s - string to escape
4
+ * @returns - the escaped string.
5
+ */
6
+ export declare function escapeRegEx(s: string): string;
7
+ //# sourceMappingURL=regexHelper.d.mts.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Escape a string so it can be used as an exact match within a RegExp.
3
+ * @param s - string to escape
4
+ * @returns - the escaped string.
5
+ */
6
+ export function escapeRegEx(s) {
7
+ return s.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
8
+ }
@@ -0,0 +1,27 @@
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 charsetToRepMapRegEx(charset: CharacterSet | undefined, replaceWith?: string): ReplaceMap | undefined;
5
+ declare function createMapperRegExp(repMap: ReplaceMap): RegExp;
6
+ interface RepTrieNode {
7
+ rep?: string[];
8
+ children?: Record<string, RepTrieNode>;
9
+ }
10
+ interface Edit {
11
+ b: number;
12
+ e: number;
13
+ r: string;
14
+ }
15
+ export declare function createRepMapper(repMap: ReplaceMap | undefined, ignoreCharset?: string): (word: string) => string[];
16
+ declare function applyEdits(word: string, edits: Edit[]): string[];
17
+ declare function calcAllEdits(root: RepTrieNode, word: string): Edit[];
18
+ declare function createTrie(repMap: ReplaceMap | undefined, ignoreCharset?: string): RepTrieNode;
19
+ export declare const __testing__: {
20
+ charsetToRepMap: typeof charsetToRepMapRegEx;
21
+ createMapperRegExp: typeof createMapperRegExp;
22
+ createTrie: typeof createTrie;
23
+ calcAllEdits: typeof calcAllEdits;
24
+ applyEdits: typeof applyEdits;
25
+ };
26
+ export {};
27
+ //# sourceMappingURL=repMap.d.mts.map