cspell-dictionary
Advanced tools
Comparing version 6.14.3 to 6.15.0
@@ -1,3 +0,3 @@ | ||
export { createCachingDictionary, createCollection, createFailedToLoadDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, SpellingDictionaryCollection, } from './SpellingDictionary'; | ||
export type { CachingDictionary, FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary'; | ||
export { createCachingDictionary, createCollection, createFailedToLoadDictionary, createFlagWordsDictionary, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, } from './SpellingDictionary'; | ||
export type { CachingDictionary, FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryCollection, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary'; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createSpellingDictionaryFromTrieFile = exports.createSpellingDictionary = exports.createIgnoreWordsDictionary = exports.createForbiddenWordsDictionary = exports.createFailedToLoadDictionary = exports.createCollection = exports.createCachingDictionary = void 0; | ||
exports.createSpellingDictionaryFromTrieFile = exports.createSpellingDictionary = exports.createIgnoreWordsDictionary = exports.createForbiddenWordsDictionary = exports.createFlagWordsDictionary = exports.createFailedToLoadDictionary = exports.createCollection = exports.createCachingDictionary = void 0; | ||
var SpellingDictionary_1 = require("./SpellingDictionary"); | ||
@@ -8,2 +8,3 @@ Object.defineProperty(exports, "createCachingDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createCachingDictionary; } }); | ||
Object.defineProperty(exports, "createFailedToLoadDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createFailedToLoadDictionary; } }); | ||
Object.defineProperty(exports, "createFlagWordsDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createFlagWordsDictionary; } }); | ||
Object.defineProperty(exports, "createForbiddenWordsDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createForbiddenWordsDictionary; } }); | ||
@@ -10,0 +11,0 @@ Object.defineProperty(exports, "createIgnoreWordsDictionary", { enumerable: true, get: function () { return SpellingDictionary_1.createIgnoreWordsDictionary; } }); |
@@ -1,2 +0,3 @@ | ||
export declare const ignoreCase = true; | ||
export declare const ignoreCase: true; | ||
export declare const isForbiddenIgnoreCaseAndAccents: false; | ||
//# sourceMappingURL=defaults.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ignoreCase = void 0; | ||
exports.isForbiddenIgnoreCaseAndAccents = exports.ignoreCase = void 0; | ||
exports.ignoreCase = true; | ||
exports.isForbiddenIgnoreCaseAndAccents = false; | ||
//# sourceMappingURL=defaults.js.map |
@@ -75,3 +75,3 @@ "use strict"; | ||
} | ||
isForbidden(_word) { | ||
isForbidden(_word, _ignoreCase) { | ||
return false; | ||
@@ -78,0 +78,0 @@ } |
export { CachingDictionary, createCachingDictionary } from './CachingDictionary'; | ||
export { createSpellingDictionary, createFailedToLoadDictionary } from './createSpellingDictionary'; | ||
export { createForbiddenWordsDictionary } from './ForbiddenWordsDictionary'; | ||
export { createFailedToLoadDictionary, createSpellingDictionary } from './createSpellingDictionary'; | ||
export { createFlagWordsDictionary, createFlagWordsDictionary as createForbiddenWordsDictionary, } from './FlagWordsDictionary'; | ||
export { createIgnoreWordsDictionary } from './IgnoreWordsDictionary'; | ||
@@ -8,2 +8,3 @@ export type { FindOptions, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions, } from './SpellingDictionary'; | ||
export { createSpellingDictionaryFromTrieFile } from './SpellingDictionaryFromTrie'; | ||
export { createTyposDictionary } from './TyposDictionary'; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createSpellingDictionaryFromTrieFile = exports.createCollection = exports.createIgnoreWordsDictionary = exports.createForbiddenWordsDictionary = exports.createFailedToLoadDictionary = exports.createSpellingDictionary = exports.createCachingDictionary = void 0; | ||
exports.createTyposDictionary = exports.createSpellingDictionaryFromTrieFile = exports.createCollection = exports.createIgnoreWordsDictionary = exports.createForbiddenWordsDictionary = exports.createFlagWordsDictionary = exports.createSpellingDictionary = exports.createFailedToLoadDictionary = exports.createCachingDictionary = void 0; | ||
var CachingDictionary_1 = require("./CachingDictionary"); | ||
Object.defineProperty(exports, "createCachingDictionary", { enumerable: true, get: function () { return CachingDictionary_1.createCachingDictionary; } }); | ||
var createSpellingDictionary_1 = require("./createSpellingDictionary"); | ||
Object.defineProperty(exports, "createFailedToLoadDictionary", { enumerable: true, get: function () { return createSpellingDictionary_1.createFailedToLoadDictionary; } }); | ||
Object.defineProperty(exports, "createSpellingDictionary", { enumerable: true, get: function () { return createSpellingDictionary_1.createSpellingDictionary; } }); | ||
Object.defineProperty(exports, "createFailedToLoadDictionary", { enumerable: true, get: function () { return createSpellingDictionary_1.createFailedToLoadDictionary; } }); | ||
var ForbiddenWordsDictionary_1 = require("./ForbiddenWordsDictionary"); | ||
Object.defineProperty(exports, "createForbiddenWordsDictionary", { enumerable: true, get: function () { return ForbiddenWordsDictionary_1.createForbiddenWordsDictionary; } }); | ||
var FlagWordsDictionary_1 = require("./FlagWordsDictionary"); | ||
Object.defineProperty(exports, "createFlagWordsDictionary", { enumerable: true, get: function () { return FlagWordsDictionary_1.createFlagWordsDictionary; } }); | ||
Object.defineProperty(exports, "createForbiddenWordsDictionary", { enumerable: true, get: function () { return FlagWordsDictionary_1.createFlagWordsDictionary; } }); | ||
var IgnoreWordsDictionary_1 = require("./IgnoreWordsDictionary"); | ||
@@ -17,2 +18,4 @@ Object.defineProperty(exports, "createIgnoreWordsDictionary", { enumerable: true, get: function () { return IgnoreWordsDictionary_1.createIgnoreWordsDictionary; } }); | ||
Object.defineProperty(exports, "createSpellingDictionaryFromTrieFile", { enumerable: true, get: function () { return SpellingDictionaryFromTrie_1.createSpellingDictionaryFromTrieFile; } }); | ||
var TyposDictionary_1 = require("./TyposDictionary"); | ||
Object.defineProperty(exports, "createTyposDictionary", { enumerable: true, get: function () { return TyposDictionary_1.createTyposDictionary; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,11 @@ import type { ReplaceMap, DictionaryInformation } from '@cspell/cspell-types'; | ||
export interface SearchOptions { | ||
/** | ||
* Legacy compounds have been deprecated. | ||
* | ||
* @deprecated | ||
*/ | ||
useCompounds?: boolean | number | undefined; | ||
/** | ||
* Ignore Case and Accents | ||
*/ | ||
ignoreCase?: boolean | undefined; | ||
@@ -49,2 +57,3 @@ } | ||
export type HasOptions = SearchOptions; | ||
export type IgnoreCaseOption = boolean; | ||
export interface SpellingDictionaryOptions { | ||
@@ -99,5 +108,29 @@ repMap?: ReplaceMap; | ||
find(word: string, options?: SearchOptions): FindResult | undefined; | ||
isForbidden(word: string): boolean; | ||
/** | ||
* Checks if a word is forbidden. | ||
* @param word - word to check. | ||
*/ | ||
isForbidden(word: string, ignoreCaseAndAccents?: IgnoreCaseOption): boolean; | ||
/** | ||
* No Suggest words are considered correct but will not be listed when | ||
* suggestions are generated. | ||
* No Suggest words and "Ignored" words are equivalent. Ignored / no suggest words override forbidden words. | ||
* @param word - word to check | ||
* @param options - options | ||
*/ | ||
isNoSuggestWord(word: string, options: HasOptions): boolean; | ||
/** | ||
* 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 | ||
* @param word - word | ||
* @param suggestOptions - options | ||
*/ | ||
suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[]; | ||
@@ -110,2 +143,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[]>; | ||
//# sourceMappingURL=SpellingDictionary.d.ts.map |
@@ -9,3 +9,3 @@ import { SearchOptions, SpellingDictionary } from './SpellingDictionary'; | ||
declare function isWordInAnyDictionary(dicts: SpellingDictionary[], word: string, options: SearchOptions): SpellingDictionary | undefined; | ||
declare function isWordForbiddenInAnyDictionary(dicts: SpellingDictionary[], word: string): SpellingDictionary | undefined; | ||
declare function isWordForbiddenInAnyDictionary(dicts: SpellingDictionary[], word: string, ignoreCase: boolean | undefined): SpellingDictionary | undefined; | ||
export declare function isSpellingDictionaryCollection(dict: SpellingDictionary): dict is SpellingDictionaryCollection; | ||
@@ -12,0 +12,0 @@ export declare const __testing__: { |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -6,4 +29,5 @@ exports.__testing__ = exports.isSpellingDictionaryCollection = exports.createCollection = void 0; | ||
const gensequence_1 = require("gensequence"); | ||
const clean_1 = require("../util/clean"); | ||
const util_1 = require("../util/util"); | ||
const clean_1 = require("../util/clean"); | ||
const Defaults = __importStar(require("./defaults")); | ||
const SpellingDictionary_1 = require("./SpellingDictionary"); | ||
@@ -21,3 +45,2 @@ const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods"); | ||
this.type = 'SpellingDictionaryCollection'; | ||
this._isForbiddenInDict = (word) => isWordForbiddenInAnyDictionary(this.dictionaries, word); | ||
this._isNoSuggestWord = (word, options) => { | ||
@@ -39,4 +62,3 @@ if (!this.containsNoSuggestWords) | ||
const options = (0, SpellingDictionaryMethods_1.hasOptionToSearchOption)(hasOptions); | ||
const { found = false, forbidden = false, noSuggest = false, } = findInAnyDictionary(this.dictionaries, word, options) || {}; | ||
return { found, forbidden, noSuggest }; | ||
return findInAnyDictionary(this.dictionaries, word, options); | ||
} | ||
@@ -46,4 +68,5 @@ isNoSuggestWord(word, options) { | ||
} | ||
isForbidden(word) { | ||
return !!this._isForbiddenInDict(word) && !this.isNoSuggestWord(word); | ||
isForbidden(word, ignoreCaseAndAccents) { | ||
const ignoreCase = ignoreCaseAndAccents ?? Defaults.isForbiddenIgnoreCaseAndAccents; | ||
return !!this._isForbiddenInDict(word, ignoreCase) && !this.isNoSuggestWord(word, { ignoreCase }); | ||
} | ||
@@ -86,2 +109,5 @@ suggest(...args) { | ||
} | ||
_isForbiddenInDict(word, ignoreCase) { | ||
return isWordForbiddenInAnyDictionary(this.dictionaries, word, ignoreCase); | ||
} | ||
} | ||
@@ -108,4 +134,4 @@ function createCollection(dictionaries, name) { | ||
} | ||
function isWordForbiddenInAnyDictionary(dicts, word) { | ||
return (0, gensequence_1.genSequence)(dicts).first((dict) => dict.isForbidden(word)); | ||
function isWordForbiddenInAnyDictionary(dicts, word, ignoreCase) { | ||
return (0, gensequence_1.genSequence)(dicts).first((dict) => dict.isForbidden(word, ignoreCase)); | ||
} | ||
@@ -112,0 +138,0 @@ function isSpellingDictionaryCollection(dict) { |
@@ -27,3 +27,3 @@ import type { SuggestionCollector, SuggestionResult } from 'cspell-trie-lib'; | ||
isNoSuggestWord(word: string, options?: HasOptions): boolean; | ||
isForbidden(word: string): boolean; | ||
isForbidden(word: string, _ignoreCaseAndAccents?: boolean): boolean; | ||
private _isForbidden; | ||
@@ -30,0 +30,0 @@ suggest(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean): SuggestionResult[]; |
@@ -27,9 +27,9 @@ "use strict"; | ||
exports.__testing__ = exports.createSpellingDictionaryFromTrieFile = exports.SpellingDictionaryFromTrie = void 0; | ||
const sync_1 = require("@cspell/cspell-pipe/sync"); | ||
const cspell_trie_lib_1 = require("cspell-trie-lib"); | ||
const AutoCache_1 = require("../util/AutoCache"); | ||
const clean_1 = require("../util/clean"); | ||
const repMap_1 = require("../util/repMap"); | ||
const clean_1 = require("../util/clean"); | ||
const Defaults = __importStar(require("./defaults")); | ||
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods"); | ||
const AutoCache_1 = require("../util/AutoCache"); | ||
const sync_1 = require("@cspell/cspell-pipe/sync"); | ||
const Defaults = __importStar(require("./defaults")); | ||
const findWordOptionsCaseSensitive = Object.freeze({ caseSensitive: true }); | ||
@@ -128,3 +128,3 @@ const findWordOptionsNotCaseSensitive = Object.freeze({ caseSensitive: false }); | ||
} | ||
isForbidden(word) { | ||
isForbidden(word, _ignoreCaseAndAccents) { | ||
return this._isForbidden(word); | ||
@@ -131,0 +131,0 @@ } |
import { DictionaryInformation } from '@cspell/cspell-types'; | ||
import { CompoundWordsMethod, SuggestionResult, WeightMap } from 'cspell-trie-lib'; | ||
import { HasOptions, SearchOptions, SpellingDictionary, SuggestOptions } from './SpellingDictionary'; | ||
import { SuggestionResult, WeightMap } from 'cspell-trie-lib'; | ||
import { HasOptions, SearchOptions, SuggestArgs, SuggestOptions } from './SpellingDictionary'; | ||
export { impersonateCollector, suggestionCollector } from 'cspell-trie-lib'; | ||
export type FilterSuggestionsPredicate = (word: SuggestionResult) => boolean; | ||
export type SuggestArgs = Parameters<SpellingDictionary['suggest']> | Parameters<(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean) => SuggestionResult[]>; | ||
export declare const defaultNumSuggestions = 10; | ||
@@ -8,0 +7,0 @@ declare function wordSearchFormsArray(word: string, isDictionaryCaseSensitive: boolean, ignoreCase: boolean): string[]; |
@@ -1,6 +0,6 @@ | ||
type NoSuggestion = null | undefined; | ||
type SingleSuggestion = string; | ||
type MultipleSuggestions = string[]; | ||
export type TyposDefValue = MultipleSuggestions | SingleSuggestion | NoSuggestion; | ||
export type TyposDefKey = string; | ||
import type { TermsDefKey, TermValueTypo, TermValueTypoNoSuggestions, TermValueTypoWithSuggestions } from '../Terms'; | ||
export type TypoValueNoSuggestions = TermValueTypoNoSuggestions; | ||
export type TypoValueWithSuggestions = TermValueTypoWithSuggestions; | ||
export type TyposDefValue = TermValueTypo; | ||
export type TyposDefKey = TermsDefKey; | ||
/** | ||
@@ -12,8 +12,8 @@ * Typos Definition | ||
export type TyposDef = Record<TyposDefKey, TyposDefValue>; | ||
type TypoNoSuggestions = string; | ||
type TypoWithNoSuggestions = string; | ||
type TypoWithSuggestionsArray = [forbidWord: string, ...suggestions: string[]]; | ||
type TypoWithSuggestionsObj = TyposDef; | ||
type TypoWithSuggestions = TypoWithSuggestionsArray | TypoWithSuggestionsObj; | ||
export type TypoEntry = TypoNoSuggestions | TypoWithSuggestions; | ||
export type TypoEntry = TypoWithNoSuggestions | TypoWithSuggestions; | ||
export {}; | ||
//# sourceMappingURL=typos.d.ts.map |
@@ -9,3 +9,3 @@ import { TypoEntry, TyposDef } from './typos'; | ||
*/ | ||
export declare function processEntriesToTyposDef(entries: TyposDef | readonly TypoEntry[] | Record<string, unknown>): TyposDef; | ||
export declare function processEntriesToTyposDef(entries: Iterable<TypoEntry> | TyposDef | Record<string, unknown>): TyposDef; | ||
/** | ||
@@ -12,0 +12,0 @@ * Tries to parse an entry. |
@@ -36,3 +36,3 @@ "use strict"; | ||
const sugs = trimAndFilter(rawSugs); | ||
return sugs.length === 1 ? sugs[0] : sugs.length ? sugs : null; | ||
return sugs.length === 1 ? sugs[0] : sugs.length ? sugs : false; | ||
} | ||
@@ -59,4 +59,4 @@ function splitSuggestionsValue(value) { | ||
} | ||
(0, assert_1.default)(value === null || value === undefined, 'Unexpected suggestion type.'); | ||
def[key] = null; | ||
(0, assert_1.default)(value === false, 'Unexpected suggestion type.'); | ||
def[key] = false; | ||
} | ||
@@ -72,3 +72,3 @@ return def; | ||
function processEntriesToTyposDef(entries) { | ||
const def = Array.isArray(entries) ? reduceToTyposDef(entries) : entries; | ||
const def = isIterable(entries) ? reduceToTyposDef(entries) : entries; | ||
const result = sanitizeIntoTypoDef(def); | ||
@@ -126,2 +126,5 @@ (0, assert_1.default)(result); | ||
exports.parseTyposFile = parseTyposFile; | ||
function isIterable(v) { | ||
return Symbol.iterator in v; | ||
} | ||
//# sourceMappingURL=typosParser.js.map |
@@ -10,4 +10,15 @@ import { TypoEntry, TyposDef, TyposDefKey, TyposDefValue } from './typos'; | ||
export declare function createTyposDef(entries?: Iterable<[TyposDefKey, TyposDefValue]>): TyposDef; | ||
/** | ||
* Extract all suggestions. | ||
* @param typosDef - the def | ||
* @returns the set of suggestions. | ||
*/ | ||
export declare function extractAllSuggestions(typosDef: TyposDef): Set<string>; | ||
/** | ||
* Extract all words that have been explicitly ignore because they contains the `ignorePrefix`. | ||
* @param typosDef - the def | ||
* @param ignorePrefix - prefix | ||
* @returns set of ignored words with the prefix removed. | ||
*/ | ||
export declare function extractIgnoreValues(typosDef: TyposDef, ignorePrefix: string): Set<string>; | ||
//# sourceMappingURL=util.d.ts.map |
@@ -15,3 +15,3 @@ "use strict"; | ||
if (typeof entry === 'string') { | ||
def[entry] = null; | ||
def[entry] = false; | ||
return def; | ||
@@ -24,3 +24,3 @@ } | ||
const s = sugs.map((s) => s.trim()).filter((s) => !!s); | ||
def[key] = !s.length ? null : s.length === 1 ? s[0] : s; | ||
def[key] = !s.length ? false : s.length === 1 ? s[0] : s; | ||
return def; | ||
@@ -37,3 +37,3 @@ } | ||
for (const [key, value] of entries) { | ||
def[key] = value; | ||
def[key] = isDefined(value) ? value : false; | ||
} | ||
@@ -43,14 +43,23 @@ return def; | ||
exports.createTyposDef = createTyposDef; | ||
/** | ||
* Extract all suggestions. | ||
* @param typosDef - the def | ||
* @returns the set of suggestions. | ||
*/ | ||
function extractAllSuggestions(typosDef) { | ||
const allSugs = (0, sync_1.pipe)(Object.values(typosDef), (0, sync_1.opFilter)(isDefined), (0, sync_1.opConcatMap)((v) => (Array.isArray(v) ? v : [v]))); | ||
const allSugs = (0, sync_1.pipe)(Object.values(typosDef), (0, sync_1.opFilter)(hasSuggestions), (0, sync_1.opConcatMap)((v) => (Array.isArray(v) ? v : [v]))); | ||
return new Set(allSugs); | ||
} | ||
exports.extractAllSuggestions = extractAllSuggestions; | ||
/** | ||
* Extract all words that have been explicitly ignore because they contains the `ignorePrefix`. | ||
* @param typosDef - the def | ||
* @param ignorePrefix - prefix | ||
* @returns set of ignored words with the prefix removed. | ||
*/ | ||
function extractIgnoreValues(typosDef, ignorePrefix) { | ||
const sugs = extractAllSuggestions(typosDef); | ||
const pfxLen = ignorePrefix.length; | ||
const ignoreKeys = Object.keys(typosDef) | ||
return new Set(Object.keys(typosDef) | ||
.filter((k) => k.startsWith(ignorePrefix)) | ||
.map((k) => k.slice(pfxLen)); | ||
return (0, sync_1.reduce)(ignoreKeys, (sugs, word) => sugs.add(word), sugs); | ||
.map((k) => k.slice(pfxLen))); | ||
} | ||
@@ -61,2 +70,11 @@ exports.extractIgnoreValues = extractIgnoreValues; | ||
} | ||
function isString(v) { | ||
return typeof v === 'string'; | ||
} | ||
function isArray(v) { | ||
return Array.isArray(v); | ||
} | ||
function hasSuggestions(v) { | ||
return isString(v) || isArray(v); | ||
} | ||
//# sourceMappingURL=util.js.map |
@@ -1,12 +0,21 @@ | ||
import { SpellingDictionary } from './SpellingDictionary'; | ||
import { IgnoreCaseOption, SpellingDictionary } from './SpellingDictionary'; | ||
import { type TypoEntry, type TyposDef } from './Typos'; | ||
export interface TyposDictionary extends SpellingDictionary { | ||
isForbidden(word: string, ignoreCaseAndAccents?: IgnoreCaseOption): boolean; | ||
/** | ||
* Determine if the word can appear in a list of suggestions. | ||
* @param word - word | ||
* @param ignoreCaseAndAccents - ignore case. | ||
* @returns true if a word is suggested, otherwise false. | ||
*/ | ||
isSuggestedWord(word: string, ignoreCaseAndAccents?: IgnoreCaseOption): boolean; | ||
} | ||
/** | ||
* Create a dictionary where all words are to be forbidden. | ||
* @param entries - list of Typos Entries | ||
* @param name | ||
* @param source | ||
* @param options | ||
* @param name - name of dictionary | ||
* @param source - source | ||
* @returns | ||
*/ | ||
export declare function createTyposDictionary(entries: string[] | TyposDef | readonly TypoEntry[], name: string, source: string): SpellingDictionary; | ||
export declare function createTyposDictionary(entries: readonly string[] | TyposDef | Iterable<TypoEntry>, name: string, source: string): TyposDictionary; | ||
//# sourceMappingURL=TyposDictionary.d.ts.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createTyposDictionary = void 0; | ||
const sync_1 = require("@cspell/cspell-pipe/sync"); | ||
const textMappers_1 = require("../util/textMappers"); | ||
const defaults = __importStar(require("./defaults")); | ||
const Typos_1 = require("./Typos"); | ||
const util_1 = require("./Typos/util"); | ||
const symIgnore = Symbol('ignored'); | ||
class TyposDictionary { | ||
class TyposDictionaryImpl { | ||
constructor(name, source, typosDef, ignoreList) { | ||
@@ -13,3 +37,2 @@ this.name = name; | ||
this.typosDef = typosDef; | ||
this.containsNoSuggestWords = false; | ||
this.options = {}; | ||
@@ -19,3 +42,7 @@ this.type = 'typos'; | ||
this.size = Object.keys(typosDef).length; | ||
this.ignoreWords = new Set((0, sync_1.pipe)((0, util_1.extractIgnoreValues)(typosDef, '!'), (0, sync_1.opAppend)(ignoreList || []))); | ||
this.explicitIgnoreWords = (0, util_1.extractIgnoreValues)(typosDef, '!'); | ||
this.suggestions = (0, util_1.extractAllSuggestions)(typosDef); | ||
this.ignoreWords = new Set((0, sync_1.pipe)(this.explicitIgnoreWords, (0, sync_1.opAppend)(ignoreList || []))); | ||
this.suggestionsLower = new Set((0, sync_1.pipe)(this.suggestions, textMappers_1.mapperRemoveCaseAndAccents)); | ||
this.containsNoSuggestWords = this.ignoreWords.size > 0; | ||
} | ||
@@ -33,29 +60,51 @@ /** | ||
/** A more detailed search for a word, might take longer than `has` */ | ||
find(word, _options) { | ||
const found = this._findForms(word); | ||
return typeof found === 'string' ? { found, forbidden: true, noSuggest: false } : undefined; | ||
find(word, options) { | ||
const result = this._findForms(word, options?.ignoreCase ?? defaults.ignoreCase); | ||
if (result === false) | ||
return undefined; | ||
const { found, ignore } = result; | ||
return { found, forbidden: !ignore, noSuggest: ignore }; | ||
} | ||
_findForms(word) { | ||
const f = this._find(word); | ||
if (f !== false) | ||
return f; | ||
_findForms(word, ignoreCaseAndAccents) { | ||
const lcWord = word.toLowerCase(); | ||
if (lcWord === word) | ||
if (this.ignoreWords.has(word)) { | ||
return { found: word, ignore: true }; | ||
} | ||
if (this.suggestions.has(word)) { | ||
return false; | ||
return this._find(lcWord); | ||
} | ||
_find(word) { | ||
if (this.ignoreWords.has(word)) | ||
return symIgnore; | ||
} | ||
if (ignoreCaseAndAccents) { | ||
if (this.suggestionsLower.has(lcWord)) { | ||
return false; | ||
} | ||
if (this.ignoreWords.has(lcWord)) { | ||
return { found: lcWord, ignore: true }; | ||
} | ||
} | ||
if (word in this.typosDef) | ||
return word; | ||
return { found: word, ignore: false }; | ||
if (lcWord in this.typosDef) | ||
return { found: lcWord, ignore: false }; | ||
return false; | ||
} | ||
isForbidden(word) { | ||
const found = this._findForms(word); | ||
return typeof found === 'string'; | ||
isForbidden(word, ignoreCaseAndAccents = defaults.isForbiddenIgnoreCaseAndAccents) { | ||
const found = this._findForms(word, ignoreCaseAndAccents); | ||
return found !== false && !found.ignore; | ||
} | ||
isNoSuggestWord(_word, _options) { | ||
return false; | ||
isNoSuggestWord(word, options) { | ||
const result = this.find(word, options); | ||
return result?.noSuggest ?? false; | ||
} | ||
/** | ||
* Determine if the word can appear in a list of suggestions. | ||
* @param word - word | ||
* @param ignoreCaseAndAccents - ignore case. | ||
* @returns true if a word is suggested, otherwise false. | ||
*/ | ||
isSuggestedWord(word, ignoreCaseAndAccents = defaults.isForbiddenIgnoreCaseAndAccents) { | ||
if (this.suggestions.has(word)) | ||
return true; | ||
const lcWord = word.toLowerCase(); | ||
return ignoreCaseAndAccents && (this.suggestions.has(lcWord) || this.suggestionsLower.has(lcWord)); | ||
} | ||
suggest(word) { | ||
@@ -97,5 +146,4 @@ return this._suggest(word) || this._suggest(word.toLowerCase()) || []; | ||
* @param entries - list of Typos Entries | ||
* @param name | ||
* @param source | ||
* @param options | ||
* @param name - name of dictionary | ||
* @param source - source | ||
* @returns | ||
@@ -105,5 +153,5 @@ */ | ||
const def = (0, Typos_1.processEntriesToTyposDef)(entries); | ||
return new TyposDictionary(name, source, def); | ||
return new TyposDictionaryImpl(name, source, def); | ||
} | ||
exports.createTyposDictionary = createTyposDictionary; | ||
//# sourceMappingURL=TyposDictionary.js.map |
{ | ||
"name": "cspell-dictionary", | ||
"version": "6.14.3", | ||
"version": "6.15.0", | ||
"description": "A spelling dictionary library useful for checking words and getting suggestions.", | ||
@@ -46,9 +46,9 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@cspell/cspell-pipe": "6.14.3", | ||
"@cspell/cspell-types": "6.14.3", | ||
"cspell-trie-lib": "6.14.3", | ||
"@cspell/cspell-pipe": "6.15.0", | ||
"@cspell/cspell-types": "6.15.0", | ||
"cspell-trie-lib": "6.15.0", | ||
"fast-equals": "^4.0.3", | ||
"gensequence": "^4.0.2" | ||
}, | ||
"gitHead": "df0efdbb0dc7b084579130ba5fe97441c0ab67ca" | ||
"gitHead": "8bbc20a6fabe0b95caafb7dac2035764cc73ba13" | ||
} |
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
92261
59
2170
+ Added@cspell/cspell-pipe@6.15.0(transitive)
+ Added@cspell/cspell-types@6.15.0(transitive)
+ Addedcspell-trie-lib@6.15.0(transitive)
- Removed@cspell/cspell-pipe@6.14.3(transitive)
- Removed@cspell/cspell-types@6.14.3(transitive)
- Removedcspell-trie-lib@6.14.3(transitive)
Updated@cspell/cspell-pipe@6.15.0
Updated@cspell/cspell-types@6.15.0
Updatedcspell-trie-lib@6.15.0