UNPKG

@dcoffey/espells

Version:

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

25 lines (24 loc) 923 B
/** Classic trie data structure. */ export declare class Trie<T> { /** Entrypoint for the trie. */ private head; /** * Adds a word to the trie, which will point to a value. * * @param word - The word to add. * @param addValue - A callback function for how to add the word to the * trie. It is provided the current value of the word added, if any. * This allows for merging overlapping values. */ add(word: string, addValue?: (cur?: T) => T): void; /** Determines if a word is in the trie. */ has(word: string): boolean; /** Returns the segments found when traversing the trie for the given word. */ segments(word: string): T[] | null; /** Returns the longest/last segment for a word. */ lastSegment(word: string): T | null; /** Removes a word from the trie. */ remove(word: string): void; private traverse; private tryDelete; }