UNPKG

@picosearch/trie

Version:

Simple, zero dependency, type-safe implementation of a trie data structure.

31 lines (30 loc) 871 B
export type TrieMapNode<T> = [ children: { [part: string]: TrieMapNode<T>; }, values?: T[] ]; export interface IFuzzySearchOptions { maxErrors?: number; limit?: number; includeValues?: boolean; } export interface ITrieMap<T> { insert: (key: string, ...values: T[]) => void; lookup: (key: string) => T[] | null; getFuzzyMatches: { (query: string, options?: IFuzzySearchOptions & { includeValues?: false; }): string[]; (query: string, options?: IFuzzySearchOptions & { includeValues: true; }): [string, T[]][]; }; toJSON: () => string; } export interface ITrie { insert: (key: string) => void; has: (key: string) => boolean; getFuzzyMatches: (query: string, options?: Omit<IFuzzySearchOptions, 'includeValues'>) => string[]; toJSON: () => string; }