cspell-dictionary
Advanced tools
Comparing version 7.0.0-alpha.2 to 7.0.0
export type { CachingDictionary, FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryCollection, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary/index.js'; | ||
export { createCachingDictionary, createCollection, createFailedToLoadDictionary, createFlagWordsDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createInlineSpellingDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, createSuggestDictionary, } from './SpellingDictionary/index.js'; | ||
export { createCachingDictionary, createCollection, createFailedToLoadDictionary, createFlagWordsDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createInlineSpellingDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, createSuggestDictionary, createSuggestOptions, } from './SpellingDictionary/index.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
export { createCachingDictionary, createCollection, createFailedToLoadDictionary, createFlagWordsDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createInlineSpellingDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, createSuggestDictionary, } from './SpellingDictionary/index.js'; | ||
export { createCachingDictionary, createCollection, createFailedToLoadDictionary, createFlagWordsDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createInlineSpellingDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, createSuggestDictionary, createSuggestOptions, } from './SpellingDictionary/index.js'; |
@@ -1,2 +0,2 @@ | ||
import { buildTrieFast, parseDictionaryLines } from 'cspell-trie-lib'; | ||
import { buildITrieFromWords, parseDictionaryLines } from 'cspell-trie-lib'; | ||
import { deepEqual } from 'fast-equals'; | ||
@@ -40,3 +40,3 @@ import { AutoWeakCache, SimpleCache } from '../util/simpleCache.js'; | ||
const words = parseDictionaryLines(wordList, parseOptions); | ||
const trie = buildTrieFast(words); | ||
const trie = buildITrieFromWords(words); | ||
const opts = { ...(options || defaultOptions) }; | ||
@@ -43,0 +43,0 @@ if (opts.weightMap === undefined && opts.dictionaryInformation) { |
import { opMap, pipe } from '@cspell/cspell-pipe/sync'; | ||
import { buildTrieFast, parseDictionaryLines } from 'cspell-trie-lib'; | ||
import { buildITrieFromWords, parseDictionaryLines } from 'cspell-trie-lib'; | ||
import { createAutoResolveWeakCache } from '../util/AutoResolve.js'; | ||
@@ -7,3 +7,2 @@ import * as Defaults from './defaults.js'; | ||
import { SpellingDictionaryFromTrie } from './SpellingDictionaryFromTrie.js'; | ||
import { suggestArgsToSuggestOptions } from './SpellingDictionaryMethods.js'; | ||
import { createTyposDictionary } from './TyposDictionary.js'; | ||
@@ -80,5 +79,3 @@ class FlagWordsDictionaryTrie extends SpellingDictionaryFromTrie { | ||
} | ||
suggest(...args) { | ||
const [word] = args; | ||
const suggestOptions = suggestArgsToSuggestOptions(args); | ||
suggest(word, suggestOptions = {}) { | ||
return this.dictTypos.suggest(word, suggestOptions); | ||
@@ -124,3 +121,3 @@ } | ||
function buildTrieDict(words, name, source) { | ||
const trie = buildTrieFast(pipe(words, opMap((w) => '!' + w), opMap((w) => w.replace(regExpCleanIgnore, '')))); | ||
const trie = buildITrieFromWords(pipe(words, opMap((w) => '!' + w), opMap((w) => w.replace(regExpCleanIgnore, '')))); | ||
return new FlagWordsDictionaryTrie(trie, name, source); | ||
@@ -127,0 +124,0 @@ } |
@@ -6,7 +6,10 @@ export { CachingDictionary, createCachingDictionary } from './CachingDictionary.js'; | ||
export { createIgnoreWordsDictionary } from './IgnoreWordsDictionary.js'; | ||
export type { DictionaryDefinitionInline, FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary.js'; | ||
export type { DictionaryDefinitionInline, FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, } from './SpellingDictionary.js'; | ||
export { createCollection, SpellingDictionaryCollection } from './SpellingDictionaryCollection.js'; | ||
export { createSpellingDictionaryFromTrieFile } from './SpellingDictionaryFromTrie.js'; | ||
export { createSuggestDictionary } from './SuggestDictionary.js'; | ||
export type { SuggestOptions } from './SuggestOptions.js'; | ||
export { createSuggestOptions } from './SuggestOptions.js'; | ||
export { createTyposDictionary } from './TyposDictionary.js'; | ||
export { CompoundWordsMethod, type SuggestionCollector, type SuggestionResult } from 'cspell-trie-lib'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -9,2 +9,4 @@ export { createCachingDictionary } from './CachingDictionary.js'; | ||
export { createSuggestDictionary } from './SuggestDictionary.js'; | ||
export { createSuggestOptions } from './SuggestOptions.js'; | ||
export { createTyposDictionary } from './TyposDictionary.js'; | ||
export { CompoundWordsMethod } from 'cspell-trie-lib'; |
import type { DictionaryInformation, ReplaceMap } from '@cspell/cspell-types'; | ||
import type { CompoundWordsMethod, SuggestionCollector, SuggestionResult, WeightMap } from 'cspell-trie-lib'; | ||
import type { SuggestionCollector, SuggestionResult, WeightMap } from 'cspell-trie-lib'; | ||
import type { SuggestOptions } from './SuggestOptions.js'; | ||
export type { DictionaryDefinitionInline } from '@cspell/cspell-types'; | ||
export { CompoundWordsMethod, type SuggestionCollector, type SuggestionResult } from 'cspell-trie-lib'; | ||
export interface SearchOptions { | ||
@@ -17,32 +17,2 @@ /** | ||
} | ||
export interface SuggestOptions { | ||
/** | ||
* Compounding Mode. | ||
* `NONE` is the best option. | ||
*/ | ||
compoundMethod?: CompoundWordsMethod | undefined; | ||
/** | ||
* The limit on the number of suggestions to generate. If `allowTies` is true, it is possible | ||
* for more suggestions to be generated. | ||
*/ | ||
numSuggestions?: number | undefined; | ||
/** | ||
* Max number of changes / edits to the word to get to a suggestion matching suggestion. | ||
*/ | ||
numChanges?: number | undefined; | ||
/** | ||
* Allow for case-ingestive checking. | ||
*/ | ||
ignoreCase?: boolean | undefined; | ||
/** | ||
* If multiple suggestions have the same edit / change "cost", then included them even if | ||
* it causes more than `numSuggestions` to be returned. | ||
* @default false | ||
*/ | ||
includeTies?: boolean | undefined; | ||
/** | ||
* Maximum amount of time to allow for generating suggestions. | ||
*/ | ||
timeout?: number | undefined; | ||
} | ||
export type FindOptions = SearchOptions; | ||
@@ -129,11 +99,2 @@ export interface Suggestion { | ||
/** | ||
* Generate suggestions for a word. | ||
* @param word - word | ||
* @param numSuggestions - max number of suggestions to generate. | ||
* @param compoundMethod - Default NONE. | ||
* @param numChanges - Default 5 | ||
* @param ignoreCase - true | ||
*/ | ||
suggest(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean): SuggestionResult[]; | ||
/** | ||
* Generate suggestions for a word | ||
@@ -143,3 +104,3 @@ * @param word - word | ||
*/ | ||
suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[]; | ||
suggest(word: string, suggestOptions?: SuggestOptions): SuggestionResult[]; | ||
getPreferredSuggestions?: (word: string) => PreferredSuggestion[]; | ||
@@ -159,4 +120,3 @@ genSuggestions(collector: SuggestionCollector, suggestOptions: SuggestOptions): void; | ||
} | ||
export type SuggestArgs = Parameters<SpellingDictionary['suggest']> | Parameters<(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean) => SuggestionResult[]>; | ||
export declare const defaultOptions: SpellingDictionaryOptions; | ||
//# sourceMappingURL=SpellingDictionary.d.ts.map |
@@ -1,4 +0,3 @@ | ||
export { CompoundWordsMethod } from 'cspell-trie-lib'; | ||
export const defaultOptions = Object.freeze({ | ||
weightMap: undefined, | ||
}); |
@@ -1,7 +0,6 @@ | ||
import { CASE_INSENSITIVE_PREFIX } from 'cspell-trie-lib'; | ||
import { CASE_INSENSITIVE_PREFIX, CompoundWordsMethod } from 'cspell-trie-lib'; | ||
import { genSequence } from 'gensequence'; | ||
import { isDefined } from '../util/util.js'; | ||
import * as Defaults from './defaults.js'; | ||
import { CompoundWordsMethod } from './SpellingDictionary.js'; | ||
import { defaultNumSuggestions, hasOptionToSearchOption, suggestArgsToSuggestOptions, suggestionCollector, } from './SpellingDictionaryMethods.js'; | ||
import { defaultNumSuggestions, hasOptionToSearchOption, suggestionCollector } from './SpellingDictionaryMethods.js'; | ||
function identityString(w) { | ||
@@ -42,5 +41,3 @@ return w; | ||
} | ||
suggest(...args) { | ||
const [word] = args; | ||
const suggestOptions = suggestArgsToSuggestOptions(args); | ||
suggest(word, suggestOptions = {}) { | ||
return this._suggest(word, suggestOptions); | ||
@@ -47,0 +44,0 @@ } |
@@ -1,6 +0,7 @@ | ||
import type { SuggestionCollector, SuggestionResult } from 'cspell-trie-lib'; | ||
import { CompoundWordsMethod, Trie } from 'cspell-trie-lib'; | ||
import type { FindResult, HasOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestOptions } from './SpellingDictionary.js'; | ||
/// <reference types="node" resolution-mode="require"/> | ||
import type { ITrie, SuggestionCollector, SuggestionResult } from 'cspell-trie-lib'; | ||
import type { FindResult, HasOptions, SpellingDictionary, SpellingDictionaryOptions } from './SpellingDictionary.js'; | ||
import type { SuggestOptions } from './SuggestOptions.js'; | ||
export declare class SpellingDictionaryFromTrie implements SpellingDictionary { | ||
readonly trie: Trie; | ||
readonly trie: ITrie; | ||
readonly name: string; | ||
@@ -19,3 +20,3 @@ readonly options: SpellingDictionaryOptions; | ||
private weightMap; | ||
constructor(trie: Trie, name: string, options: SpellingDictionaryOptions, source?: string, size?: number); | ||
constructor(trie: ITrie, name: string, options: SpellingDictionaryOptions, source?: string, size?: number); | ||
get size(): number; | ||
@@ -31,4 +32,3 @@ has(word: string, hasOptions?: HasOptions): boolean; | ||
private _isForbidden; | ||
suggest(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean): SuggestionResult[]; | ||
suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[]; | ||
suggest(word: string, suggestOptions?: SuggestOptions): SuggestionResult[]; | ||
private _suggest; | ||
@@ -46,3 +46,3 @@ genSuggestions(collector: SuggestionCollector, suggestOptions: SuggestOptions): void; | ||
*/ | ||
export declare function createSpellingDictionaryFromTrieFile(data: Iterable<string> | string, name: string, source: string, options: SpellingDictionaryOptions): SpellingDictionary; | ||
export declare function createSpellingDictionaryFromTrieFile(data: string | Buffer, name: string, source: string, options: SpellingDictionaryOptions): SpellingDictionary; | ||
declare function outerWordForms(word: string, mapWord: (word: string) => string[]): Set<string>; | ||
@@ -49,0 +49,0 @@ export declare const __testing__: { |
import { opConcatMap, pipe } from '@cspell/cspell-pipe/sync'; | ||
import { CompoundWordsMethod, importTrie, suggestionCollector, Trie } from 'cspell-trie-lib'; | ||
import { CompoundWordsMethod, decodeTrie, suggestionCollector } from 'cspell-trie-lib'; | ||
import { autoCache, createCache01 } from '../util/AutoCache.js'; | ||
@@ -7,6 +7,6 @@ import { clean } from '../util/clean.js'; | ||
import * as Defaults from './defaults.js'; | ||
import { createWeightMapFromDictionaryInformation, defaultNumSuggestions, hasOptionToSearchOption, impersonateCollector, suggestArgsToSuggestOptions, wordSearchForms, wordSuggestFormsArray, } from './SpellingDictionaryMethods.js'; | ||
import { createWeightMapFromDictionaryInformation, defaultNumSuggestions, hasOptionToSearchOption, impersonateCollector, wordSearchForms, wordSuggestFormsArray, } from './SpellingDictionaryMethods.js'; | ||
const findWordOptionsCaseSensitive = Object.freeze({ caseSensitive: true }); | ||
const findWordOptionsNotCaseSensitive = Object.freeze({ caseSensitive: false }); | ||
class SpellingDictionaryFromTrie { | ||
export class SpellingDictionaryFromTrie { | ||
constructor(trie, name, options, source = 'from trie', size) { | ||
@@ -27,3 +27,3 @@ this.trie = trie; | ||
this.remapWord = createRepMapper(options.repMap, options.dictionaryInformation?.ignore); | ||
this.isDictionaryCaseSensitive = options.caseSensitive ?? !trie.isLegacy; | ||
this.isDictionaryCaseSensitive = options.caseSensitive ?? trie.isCaseAware; | ||
this.containsNoSuggestWords = options.noSuggest || false; | ||
@@ -107,5 +107,3 @@ this._size = size || 0; | ||
} | ||
suggest(...args) { | ||
const [word] = args; | ||
const suggestOptions = suggestArgsToSuggestOptions(args); | ||
suggest(word, suggestOptions = {}) { | ||
return this._suggest(word, suggestOptions); | ||
@@ -142,3 +140,2 @@ } | ||
SpellingDictionaryFromTrie.cachedWordsLimit = 50000; | ||
export { SpellingDictionaryFromTrie }; | ||
/** | ||
@@ -153,5 +150,3 @@ * Create a dictionary from a trie file. | ||
export function createSpellingDictionaryFromTrieFile(data, name, source, options) { | ||
data = typeof data === 'string' ? data.split('\n') : data; | ||
const trieNode = importTrie(data); | ||
const trie = new Trie(trieNode); | ||
const trie = decodeTrie(data); | ||
return new SpellingDictionaryFromTrie(trie, name, options, source); | ||
@@ -158,0 +153,0 @@ } |
import type { DictionaryInformation } from '@cspell/cspell-types'; | ||
import type { SuggestionResult, WeightMap } from 'cspell-trie-lib'; | ||
import type { HasOptions, SearchOptions, SuggestArgs, SuggestOptions } from './SpellingDictionary.js'; | ||
import type { HasOptions, SearchOptions } from './SpellingDictionary.js'; | ||
export { impersonateCollector, suggestionCollector } from 'cspell-trie-lib'; | ||
@@ -18,3 +18,2 @@ export type FilterSuggestionsPredicate = (word: SuggestionResult) => boolean; | ||
export declare function canonicalSearchOptions(opt: SearchOptions): SearchOptions; | ||
export declare function suggestArgsToSuggestOptions(args: SuggestArgs): SuggestOptions; | ||
export declare function createWeightMapFromDictionaryInformation(di: undefined): undefined; | ||
@@ -21,0 +20,0 @@ export declare function createWeightMapFromDictionaryInformation(di: DictionaryInformation): WeightMap; |
@@ -78,14 +78,2 @@ import { mapDictionaryInformationToWeightMap } from 'cspell-trie-lib'; | ||
} | ||
export function suggestArgsToSuggestOptions(args) { | ||
const [_word, options, compoundMethod, numChanges, ignoreCase] = args; | ||
const suggestOptions = typeof options === 'object' | ||
? options | ||
: { | ||
numSuggestions: options, | ||
compoundMethod, | ||
numChanges, | ||
ignoreCase, | ||
}; | ||
return suggestOptions; | ||
} | ||
export function createWeightMapFromDictionaryInformation(di) { | ||
@@ -92,0 +80,0 @@ return di ? mapDictionaryInformationToWeightMap(di) : undefined; |
{ | ||
"name": "cspell-dictionary", | ||
"version": "7.0.0-alpha.2", | ||
"version": "7.0.0", | ||
"description": "A spelling dictionary library useful for checking words and getting suggestions.", | ||
@@ -50,9 +50,9 @@ "type": "module", | ||
"dependencies": { | ||
"@cspell/cspell-pipe": "7.0.0-alpha.2", | ||
"@cspell/cspell-types": "7.0.0-alpha.2", | ||
"cspell-trie-lib": "7.0.0-alpha.2", | ||
"@cspell/cspell-pipe": "7.0.0", | ||
"@cspell/cspell-types": "7.0.0", | ||
"cspell-trie-lib": "7.0.0", | ||
"fast-equals": "^4.0.3", | ||
"gensequence": "^5.0.2" | ||
}, | ||
"gitHead": "a1b7c5daeef5afdb14d6444318f450b9fd9c035a" | ||
"gitHead": "52960d5ed75655978f9b633f44fd106937a63cd7" | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
67
0
0
90794
2344
8
+ Added@cspell/cspell-pipe@7.0.0(transitive)
+ Added@cspell/cspell-types@7.0.0(transitive)
+ Addedcspell-trie-lib@7.0.0(transitive)
- Removed@cspell/cspell-pipe@7.0.0-alpha.2(transitive)
- Removed@cspell/cspell-types@7.0.0-alpha.2(transitive)
- Removedcspell-trie-lib@7.0.0-alpha.2(transitive)
Updated@cspell/cspell-pipe@7.0.0
Updated@cspell/cspell-types@7.0.0
Updatedcspell-trie-lib@7.0.0