cspell-dictionary
Advanced tools
Comparing version 6.29.3 to 6.30.0
import type { CacheStats } from '../util/AutoCache.js'; | ||
import type { SearchOptions, SpellingDictionary } from './SpellingDictionary.js'; | ||
import type { PreferredSuggestion, SearchOptions, SpellingDictionary } from './SpellingDictionary.js'; | ||
import type { SpellingDictionaryCollection } from './SpellingDictionaryCollection.js'; | ||
@@ -10,2 +10,3 @@ interface CallStats { | ||
isForbidden: CacheStats; | ||
getPreferredSuggestions: CacheStats; | ||
} | ||
@@ -22,2 +23,3 @@ /** | ||
stats(): CallStats; | ||
getPreferredSuggestions(word: string): PreferredSuggestion[] | undefined; | ||
} | ||
@@ -24,0 +26,0 @@ /** |
@@ -7,2 +7,3 @@ "use strict"; | ||
let dictionaryCounter = 0; | ||
const DefaultAutoCacheSize = 1000; | ||
class CachedDict { | ||
@@ -13,5 +14,6 @@ constructor(dict, options) { | ||
this.id = ++dictionaryCounter; | ||
this.has = (0, AutoCache_js_1.autoCache)((word) => this.dict.has(word, this.options)); | ||
this.isNoSuggestWord = (0, AutoCache_js_1.autoCache)((word) => this.dict.isNoSuggestWord(word, this.options)); | ||
this.isForbidden = (0, AutoCache_js_1.autoCache)((word) => this.dict.isForbidden(word)); | ||
this.has = (0, AutoCache_js_1.autoCache)((word) => this.dict.has(word, this.options), DefaultAutoCacheSize); | ||
this.isNoSuggestWord = (0, AutoCache_js_1.autoCache)((word) => this.dict.isNoSuggestWord(word, this.options), DefaultAutoCacheSize); | ||
this.isForbidden = (0, AutoCache_js_1.autoCache)((word) => this.dict.isForbidden(word), DefaultAutoCacheSize); | ||
this.getPreferredSuggestions = (0, AutoCache_js_1.autoCache)((word) => this.dict.getPreferredSuggestions?.(word), DefaultAutoCacheSize); | ||
this.name = dict.name; | ||
@@ -27,2 +29,3 @@ // console.log(`CachedDict for ${this.name}`); | ||
isForbidden: (0, AutoCache_js_1.extractStats)(this.isForbidden), | ||
getPreferredSuggestions: (0, AutoCache_js_1.extractStats)(this.getPreferredSuggestions), | ||
}; | ||
@@ -29,0 +32,0 @@ } |
@@ -110,2 +110,5 @@ "use strict"; | ||
} | ||
getPreferredSuggestions(word) { | ||
return this.dictTypos.getPreferredSuggestions(word); | ||
} | ||
genSuggestions() { | ||
@@ -112,0 +115,0 @@ return; |
@@ -48,2 +48,9 @@ import type { DictionaryInformation, ReplaceMap } from '@cspell/cspell-types'; | ||
export type FindOptions = SearchOptions; | ||
export interface Suggestion { | ||
word: string; | ||
isPreferred?: boolean | undefined; | ||
} | ||
export interface PreferredSuggestion extends Suggestion { | ||
isPreferred: true; | ||
} | ||
export interface FindResult { | ||
@@ -136,2 +143,3 @@ /** the text found, otherwise `false` */ | ||
suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[]; | ||
getPreferredSuggestions?: (word: string) => PreferredSuggestion[]; | ||
genSuggestions(collector: SuggestionCollector, suggestOptions: SuggestOptions): void; | ||
@@ -138,0 +146,0 @@ mapWord(word: string): string; |
@@ -91,3 +91,3 @@ "use strict"; | ||
this.genSuggestions(collector, suggestOptions); | ||
return collector.suggestions.map((r) => ({ ...r, word: r.word })); | ||
return collector.suggestions; | ||
} | ||
@@ -97,2 +97,14 @@ get size() { | ||
} | ||
getPreferredSuggestions(word) { | ||
const sugs = this.dictionaries.flatMap((dict) => dict.getPreferredSuggestions?.(word)).filter(util_js_1.isDefined); | ||
if (sugs.length <= 1) | ||
return sugs; | ||
const unique = new Set(); | ||
return sugs.filter((sug) => { | ||
if (unique.has(sug.word)) | ||
return false; | ||
unique.add(sug.word); | ||
return true; | ||
}); | ||
} | ||
genSuggestions(collector, suggestOptions) { | ||
@@ -99,0 +111,0 @@ const _suggestOptions = { ...suggestOptions }; |
@@ -1,4 +0,5 @@ | ||
import type { IgnoreCaseOption, SpellingDictionary } from './SpellingDictionary.js'; | ||
import type { IgnoreCaseOption, PreferredSuggestion, SpellingDictionary } from './SpellingDictionary.js'; | ||
import { type TypoEntry, type TyposDef } from './Typos/index.js'; | ||
export interface SuggestDictionary extends SpellingDictionary { | ||
getPreferredSuggestions: (word: string) => PreferredSuggestion[]; | ||
/** | ||
@@ -5,0 +6,0 @@ * Determine if the word can appear in a list of suggestions. |
@@ -79,3 +79,3 @@ "use strict"; | ||
suggest(word) { | ||
return this._suggest(word) || this._suggest(word.toLowerCase()) || []; | ||
return this.getPreferredSuggestions(word); | ||
} | ||
@@ -100,2 +100,5 @@ _suggest(word) { | ||
} | ||
getPreferredSuggestions(word) { | ||
return this._suggest(word) || this._suggest(word.toLowerCase()) || []; | ||
} | ||
genSuggestions(collector) { | ||
@@ -102,0 +105,0 @@ const sugs = this.suggest(collector.word); |
@@ -1,4 +0,5 @@ | ||
import type { IgnoreCaseOption, SpellingDictionary } from './SpellingDictionary.js'; | ||
import type { IgnoreCaseOption, PreferredSuggestion, SpellingDictionary } from './SpellingDictionary.js'; | ||
import { type TypoEntry, type TyposDef } from './Typos/index.js'; | ||
export interface TyposDictionary extends SpellingDictionary { | ||
getPreferredSuggestions: (word: string) => PreferredSuggestion[]; | ||
isForbidden(word: string, ignoreCaseAndAccents?: IgnoreCaseOption): boolean; | ||
@@ -5,0 +6,0 @@ /** |
@@ -109,3 +109,3 @@ "use strict"; | ||
suggest(word) { | ||
return this._suggest(word) || this._suggest(word.toLowerCase()) || []; | ||
return this.getPreferredSuggestions(word); | ||
} | ||
@@ -136,2 +136,5 @@ _suggest(word) { | ||
} | ||
getPreferredSuggestions(word) { | ||
return this._suggest(word) || this._suggest(word.toLowerCase()) || []; | ||
} | ||
mapWord(word) { | ||
@@ -138,0 +141,0 @@ return word; |
{ | ||
"name": "cspell-dictionary", | ||
"version": "6.29.3", | ||
"version": "6.30.0", | ||
"description": "A spelling dictionary library useful for checking words and getting suggestions.", | ||
@@ -55,9 +55,9 @@ "type": "commonjs", | ||
"dependencies": { | ||
"@cspell/cspell-pipe": "6.29.3", | ||
"@cspell/cspell-types": "6.29.3", | ||
"cspell-trie-lib": "6.29.3", | ||
"@cspell/cspell-pipe": "6.30.0", | ||
"@cspell/cspell-types": "6.30.0", | ||
"cspell-trie-lib": "6.30.0", | ||
"fast-equals": "^4.0.3", | ||
"gensequence": "^5.0.2" | ||
}, | ||
"gitHead": "a46e27dd5e9d52d83f0bfdbeeafcda58ca516fc1" | ||
"gitHead": "9af8c211fdeeb58e2d7a2be0e72405a23fe954cc" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
202594
4420
+ Added@cspell/cspell-pipe@6.30.0(transitive)
+ Added@cspell/cspell-types@6.30.0(transitive)
+ Addedcspell-trie-lib@6.30.0(transitive)
- Removed@cspell/cspell-pipe@6.29.3(transitive)
- Removed@cspell/cspell-types@6.29.3(transitive)
- Removedcspell-trie-lib@6.29.3(transitive)
Updated@cspell/cspell-pipe@6.30.0
Updated@cspell/cspell-types@6.30.0
Updatedcspell-trie-lib@6.30.0