import { PlainObject } from "../models.mjs"; //#region src/string/fuzzy.d.ts /** * Fuzzy searcher for an array of items */ declare class Fuzzy { #private; /** * Get items currently being searched through * * @returns Original items */ get items(): Item[]; /** * Set new items to search through * * @param items New items to search through */ set items(items: Item[]); /** * Get strings currently being searched through _(the stringified version of `items`)_ * * @returns Stringified items */ get strings(): string[]; constructor(state: FuzzyState); /** * Search for items matching the given value * * @param value Value to search for * @param options Search options * @returns Search results, with exact matches _(ordered)_ and similar matches _(ordered by relevance)_ */ search(value: string, options?: FuzzyOptions): FuzzyResult; /** * Search for items matching the given value * * @param value Value to search for * @param limit Maximum number of combined items to return in `exact` and `similar` * @returns Search results, with exact matches _(ordered)_ and similar matches _(ordered by relevance)_ */ search(value: string, limit: number): FuzzyResult; } type FuzzyConfiguration = { /** * Handler to stringify items * * - May be a function that takes an item and returns a string, or if items are plain objects, a key of the item to use to grab a string value from * - Defaults to `getString` */ handler?: (item: Item) => string; } & (Item extends PlainObject ? { /** * Key to use to stringify items * * _Prioritized over `handler`_ */ key?: keyof Item; } : {}) & FuzzyOptions; type FuzzyOptions = { /** * Maximum number of combined items to return in `exact` and `similar` _(defaults to all matches)_ */ limit?: number; /** * Maximum score difference between the best and worst similar matches included in results * * - Higher values cast a wider net * - Defaults to `5` */ tolerance?: number; }; /** * Search results from a fuzzy search, with exact and similar matches */ type FuzzyResult = { /** * Ordered items that exactly match the search value */ exact: Item[]; /** * Ordered items that are similar to the search value, ranked by relevance */ similar: Item[]; }; /** * Options for fuzzy searching */ type FuzzySearchOptions = FuzzyOptions; type FuzzyState = { handler: (item: Item) => string; items: Item[]; limit?: number; strings: string[]; tolerance: number; }; /** * Create a fuzzy searcher for an array of items * * @param items Items to search through * @param key Key to use to stringify items * @returns Fuzzy searcher */ declare function fuzzy(items: Item[], key?: ItemKey): Fuzzy; /** * Create a fuzzy searcher for an array of items * * @param items Items to search through * @param handler Handler to stringify items * @returns Fuzzy searcher */ declare function fuzzy(items: Item[], handler?: (item: Item) => string): Fuzzy; /** * Create a fuzzy searcher for an array of items * * @param items Items to search through * @param configuration Fuzzy configuration * @returns Fuzzy searcher */ declare function fuzzy(items: Item[], configuration?: FuzzyConfiguration): Fuzzy; declare namespace fuzzy { var match: typeof fuzzyMatch; } /** * Does the needle match the haystack in a fuzzy way? * * @param haystack Haystack to search through * @param needle Needle to search for * @returns `true` if the needle matches the haystack in a fuzzy way, `false` otherwise */ declare function fuzzyMatch(haystack: string, needle: string): boolean; //#endregion export { FuzzyConfiguration, FuzzyOptions, FuzzyResult, FuzzySearchOptions, fuzzy, fuzzyMatch };