UNPKG

@dcoffey/espells

Version:

Pure JS/TS spellchecker, using Hunspell dictionaries. Based on Spylls.

52 lines (51 loc) 1.86 kB
import type { Aff, Flag, Flags, FlagSet } from "../aff/index.js"; import type { Prefix, Suffix } from "../aff/affix.js"; import { CapType } from "../constants.js"; /** A word as found in a {@link Dic} instance's index. */ export declare class Word { private aff; /** The raw stem of the word, as parsed from the `.dic` file. */ stem: string; /** The capitalization type of this word. */ capType: CapType; /** The {@link Flags} that this word is associated with. */ flags?: Flags; /** * Misc. data that the word was associated with in the `.dic` file. e.g. * determining if `is:gendered` is associated with a word would be * `word.data.get("is").has("gendered")`. */ data?: Map<string, Set<string>>; /** Common misspellings for this word. */ altSpellings?: Set<string>; /** The {@link Affix} instances that apply to this word. */ affixes?: { prefixes: Set<Prefix>; suffixes: Set<Suffix>; }; /** * @param line - The line from a `.dic` file to parse. Can also just be * treated as a "word" argument. * @param aff - {@link Aff} data to use. */ constructor(line: string, aff: Aff); /** * Determines if this word has the given flag. * * @param flag - The flag to check for. Can be undefined, which will return false. */ has(flag?: Flag): boolean; /** * Returns the forms (permutations) of this {@link Word}, with all valid * suffixes and prefixes. * * @param similarTo - The string/word that the forms found should be similar to. */ forms(similarTo?: string): string[]; /** * Utility function for generating a {@link FlagSet} from an array of words. * * @param words - The words to generate the flag set from. */ static flagSets(words: Word[]): FlagSet; }