@dcoffey/espells
Version:
Pure JS/TS spellchecker, using Hunspell dictionaries. Based on Spylls.
80 lines (79 loc) • 2.78 kB
TypeScript
import type { Aff, Flag } from "../aff/index.js";
import type { Reader } from "../reader.js";
import { Word } from "./word.js";
export { Word };
/** Hunspell dictionary data. */
export declare class Dic {
/** The full set of {@link Word} entries in the dictionary. */
words: Set<Word>;
/**
* A mapping of stems to {@link Word} entries. A stem may map to multiple
* words, so the actual mapped value may either be a set or a singular
* {@link Word} instance. Most stems won't map to multiple words, so for
* the sake of saving memory a set is only used when it's actually needed.
*/
private index;
/**
* A mapping of stems that weren't lowercase to begin with to their
* {@link Word} instances.
*/
private lowercaseIndex;
/** Spellchecker {@link Aff} data to use when parsing the dictionary. */
private aff;
/**
* @param reader - The {@link Reader} instance to use when parsing.
* @param aff - The {@link Aff} data to use.
*/
constructor(reader: Reader, aff: Aff);
/**
* Utility for adding a stem + {@link Word} to a index.
*
* @param index - Index to add the stem to.
* @param stem - The stem entrypoint.
* @param word - The mapped {@link Word}.
*/
private addToIndex;
/**
* Utility for getting a {@link Word} set from an index.
*
* @param index - The index to retrieve the {@link Word} set from.
* @param stem - The stem to search for.
*/
private getFromindex;
/**
* Adds additional dictionary data.
*
* @param reader - The {@link Reader} to parse with.
*/
addDictionary(reader: Reader): void;
/**
* Adds a word to the dictionary. Can accept flags.
*
* @param word - The word to add.
*/
add(word: Word): void;
/**
* Removes a stem and any of its associated {@link Word} instances from
* the dictionary.
*
* @param stem - The stem to remove.
*/
remove(stem: string): void;
/**
* Retrieves all of the homonyms (all associated {@link Word} instances) for a stem.
*
* @param stem - The stem to retrieve with.
* @param ignorecase - If true, the {@link Dic.lowercaseIndex} will be
* searched through as well.
*/
homonyms(stem: string, ignorecase?: boolean): Set<Word>;
/**
* Determines if the given stem has a {@link Flag} associated with it or not.
*
* @param stem - The stem to check.
* @param flag - The flag to check. Can actually be undefined - which
* will just cause the function to return false.
* @param all - If true, every homonym of the stem must have the flag given.
*/
hasFlag(stem: string, flag?: Flag, all?: boolean): boolean;
}