cspell-dictionary 9.0.1 → 9.1.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.
@@ -1,6 +1,7 @@
1
1
  import type { CacheStats } from '../util/AutoCache.js';
2
2
  import type { PreferredSuggestion, SearchOptions, SpellingDictionary } from './SpellingDictionary.js';
3
3
  import type { SpellingDictionaryCollection } from './SpellingDictionaryCollection.js';
4
+ import type { SuggestOptionsRO } from './SuggestOptions.js';
4
5
  interface CallStats {
5
6
  name: string;
6
7
  id: number;
@@ -20,6 +21,7 @@ export interface CachingDictionary {
20
21
  isForbidden(word: string): boolean;
21
22
  stats(): CallStats;
22
23
  getPreferredSuggestions(word: string): PreferredSuggestion[] | undefined;
24
+ suggest(word: string, suggestOptions?: SuggestOptionsRO): import('cspell-trie-lib').SuggestionResult[];
23
25
  }
24
26
  interface LogEntryBase extends SearchOptions {
25
27
  time: number;
@@ -28,6 +28,7 @@ class CachedDict {
28
28
  isNoSuggestWord = autoCache((word) => this.dict.isNoSuggestWord(word, this.options), DefaultAutoCacheSize);
29
29
  isForbidden = autoCache((word) => this.dict.isForbidden(word), DefaultAutoCacheSize);
30
30
  getPreferredSuggestions = autoCache((word) => this.dict.getPreferredSuggestions?.(word), DefaultAutoCacheSize);
31
+ suggest = (word, suggestOptions) => this.dict.suggest(word, suggestOptions);
31
32
  stats() {
32
33
  return {
33
34
  name: this.name,
@@ -1,4 +1,7 @@
1
1
  import type { SpellingDictionary } from './SpellingDictionary.js';
2
+ export interface CreateIgnoreWordsDictionaryOptions {
3
+ supportNonStrictSearches?: boolean | undefined;
4
+ }
2
5
  /**
3
6
  * Create a dictionary where all words are to be ignored.
4
7
  * Ignored words override forbidden words.
@@ -7,5 +10,5 @@ import type { SpellingDictionary } from './SpellingDictionary.js';
7
10
  * @param source - dictionary source
8
11
  * @returns
9
12
  */
10
- export declare function createIgnoreWordsDictionary(wordList: readonly string[], name: string, source: string): SpellingDictionary;
13
+ export declare function createIgnoreWordsDictionary(wordList: readonly string[], name: string, source: string, options?: CreateIgnoreWordsDictionaryOptions): SpellingDictionary;
11
14
  //# sourceMappingURL=IgnoreWordsDictionary.d.ts.map
@@ -82,10 +82,11 @@ const createCache = createAutoResolveWeakCache();
82
82
  * @param source - dictionary source
83
83
  * @returns
84
84
  */
85
- export function createIgnoreWordsDictionary(wordList, name, source) {
85
+ export function createIgnoreWordsDictionary(wordList, name, source, options) {
86
86
  return createCache.get(wordList, () => {
87
87
  const testSpecialCharacters = /[*+]/;
88
- const words = [...parseDictionaryLines(wordList, { stripCaseAndAccents: true })].map((w) => w.normalize(NormalizeForm));
88
+ const parseOptions = { stripCaseAndAccents: options?.supportNonStrictSearches ?? true };
89
+ const words = [...parseDictionaryLines(wordList, parseOptions)].map((w) => w.normalize(NormalizeForm));
89
90
  const hasSpecial = words.some((word) => testSpecialCharacters.test(word));
90
91
  if (hasSpecial) {
91
92
  return createSpellingDictionary(words, name, source, {
@@ -36,11 +36,11 @@ export type HasOptions = SearchOptions;
36
36
  export type HasOptionsRO = Readonly<HasOptions>;
37
37
  export type IgnoreCaseOption = boolean;
38
38
  export interface SpellingDictionaryOptions {
39
- repMap?: ReplaceMap;
39
+ repMap?: ReplaceMap | undefined;
40
40
  /**
41
41
  * The dictionary is case aware.
42
42
  */
43
- caseSensitive?: boolean;
43
+ caseSensitive?: boolean | undefined;
44
44
  /**
45
45
  * This is a NO Suggest dictionary used for words to be ignored.
46
46
  */
@@ -56,7 +56,7 @@ export interface SpellingDictionaryOptions {
56
56
  * Extra dictionary information used in improving suggestions
57
57
  * based upon locale.
58
58
  */
59
- dictionaryInformation?: DictionaryInformation;
59
+ dictionaryInformation?: DictionaryInformation | undefined;
60
60
  /**
61
61
  * Strip Case and Accents to allow for case insensitive searches and
62
62
  * words without accents.
@@ -66,12 +66,12 @@ export interface SpellingDictionaryOptions {
66
66
  *
67
67
  * @default true
68
68
  */
69
- supportNonStrictSearches?: boolean;
69
+ supportNonStrictSearches?: boolean | undefined;
70
70
  /**
71
71
  * Turns on legacy word compounds.
72
72
  * @deprecated
73
73
  */
74
- useCompounds?: boolean;
74
+ useCompounds?: boolean | undefined;
75
75
  /**
76
76
  * Optional WeightMap used to improve suggestions.
77
77
  */
@@ -56,8 +56,10 @@ class SuggestDictionaryImpl {
56
56
  isSuggestedWord(word, ignoreCaseAndAccents = defaults.isForbiddenIgnoreCaseAndAccents) {
57
57
  if (this.suggestions.has(word))
58
58
  return true;
59
+ if (!ignoreCaseAndAccents)
60
+ return false;
59
61
  const lcWord = word.toLowerCase();
60
- return ignoreCaseAndAccents && (this.suggestions.has(lcWord) || this.suggestionsLower.has(lcWord));
62
+ return this.suggestions.has(lcWord) || this.suggestionsLower.has(lcWord);
61
63
  }
62
64
  suggest(word) {
63
65
  return this.getPreferredSuggestions(word);
@@ -25,7 +25,7 @@ export interface SuggestOptions {
25
25
  */
26
26
  includeTies?: boolean | undefined;
27
27
  /**
28
- * Maximum amount of time to allow for generating suggestions.
28
+ * Maximum amount of time in milliseconds to allow for generating suggestions.
29
29
  */
30
30
  timeout?: number | undefined;
31
31
  }
@@ -8,11 +8,12 @@ import { createSuggestDictionary } from './SuggestDictionary.js';
8
8
  const cache = createAutoResolveWeakCache();
9
9
  export function createInlineSpellingDictionary(inlineDict, source) {
10
10
  return cache.get(inlineDict, () => {
11
- const { words, flagWords, ignoreWords, suggestWords, name } = inlineDict;
11
+ const { words, flagWords, ignoreWords, suggestWords, name, supportNonStrictSearches } = inlineDict;
12
+ const options = { supportNonStrictSearches };
12
13
  const dictSources = [
13
14
  words && createSpellingDictionary(words, name + '-words', source, inlineDict),
14
15
  flagWords && createFlagWordsDictionary(flagWords, name + '-flag-words', source),
15
- ignoreWords && createIgnoreWordsDictionary(ignoreWords, name + '-ignore-words', source),
16
+ ignoreWords && createIgnoreWordsDictionary(ignoreWords, name + '-ignore-words', source, options),
16
17
  suggestWords && createSuggestDictionary(suggestWords, name + '-suggest', source),
17
18
  ].filter(isDefined);
18
19
  return createCollection(dictSources, name, source);
@@ -3,7 +3,7 @@ export { createInlineSpellingDictionary } from './createInlineSpellingDictionary
3
3
  export { createFailedToLoadDictionary, createSpellingDictionary } from './createSpellingDictionary.js';
4
4
  export { createFlagWordsDictionary, createFlagWordsDictionary as createForbiddenWordsDictionary, } from './FlagWordsDictionary.js';
5
5
  export { createIgnoreWordsDictionary } from './IgnoreWordsDictionary.js';
6
- export type { DictionaryDefinitionInline, FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, } from './SpellingDictionary.js';
6
+ export type { DictionaryDefinitionInline, FindOptions, FindResult, HasOptions, PreferredSuggestion, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, } from './SpellingDictionary.js';
7
7
  export { createCollection, SpellingDictionaryCollection } from './SpellingDictionaryCollection.js';
8
8
  export { createSpellingDictionaryFromTrieFile } from './SpellingDictionaryFromTrie.js';
9
9
  export { createSuggestDictionary } from './SuggestDictionary.js';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { enableLogging as cacheDictionaryEnableLogging, getLog as cacheDictionaryGetLog } from './SpellingDictionary/CachingDictionary.js';
2
- export type { CachingDictionary, FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryCollection, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary/index.js';
2
+ export type { CachingDictionary, FindOptions, FindResult, HasOptions, PreferredSuggestion, SearchOptions, SpellingDictionary, SpellingDictionaryCollection, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary/index.js';
3
3
  export { createCachingDictionary, createCollection, createFailedToLoadDictionary, createFlagWordsDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createInlineSpellingDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, createSuggestDictionary, createSuggestOptions, } from './SpellingDictionary/index.js';
4
4
  /**
5
5
  * Debugging utilities.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public",
5
5
  "provenance": true
6
6
  },
7
- "version": "9.0.1",
7
+ "version": "9.1.0",
8
8
  "description": "A spelling dictionary library useful for checking words and getting suggestions.",
9
9
  "type": "module",
10
10
  "sideEffects": false,
@@ -54,14 +54,14 @@
54
54
  "node": ">=20"
55
55
  },
56
56
  "dependencies": {
57
- "@cspell/cspell-pipe": "9.0.1",
58
- "@cspell/cspell-types": "9.0.1",
59
- "cspell-trie-lib": "9.0.1",
57
+ "@cspell/cspell-pipe": "9.1.0",
58
+ "@cspell/cspell-types": "9.1.0",
59
+ "cspell-trie-lib": "9.1.0",
60
60
  "fast-equals": "^5.2.2"
61
61
  },
62
62
  "devDependencies": {
63
63
  "gensequence": "^7.0.0",
64
64
  "lorem-ipsum": "^2.0.8"
65
65
  },
66
- "gitHead": "bdfabd3686aac9827f3af0ceb4aa74947b5f9d60"
66
+ "gitHead": "a7ed42a31debbc86faa4a4ac2c686bdffe5b26b6"
67
67
  }