/** * Result of a fuzzy search on objects * * @typeParam T - The type of object being searched */ export interface IFuzzySearchResult { /** The matched object */ item: T; /** The index of the object in the original array */ refIndex: number; /** The match score (lower is better) */ score?: number; /** Where the search string matched, present when `includeMatches` is set */ matches?: ReadonlyArray<{ indices: ReadonlyArray; key?: string; value?: string; refIndex?: number; }>; } /** * A searchable object property with a relative weight * * Matches in a property with a higher weight rank above matches in a property * with a lower weight. Plain property names weigh 1. */ export interface IWeightedObjectKey { /** The object property name */ name: string; /** The relative weight of the property; must be a positive number */ weight: number; } /** * An object property to search: a property name or a weighted property */ export type TObjectSorterKey = string | IWeightedObjectKey; /** * Options for ObjectSorter.sort */ export interface IObjectSorterSortOptions { /** Report where the search string matched in each result (`matches`) */ includeMatches?: boolean; } /** * Handles fuzzy searching and sorting of objects based on their properties * * @typeParam T - The type of objects to search through * * @example * ```typescript * interface User { * name: string; * email: string; * } * * const users = [ * { name: 'John Smith', email: 'john@example.com' }, * { name: 'Jane Doe', email: 'jane@example.com' } * ]; * * const sorter = new ObjectSorter(users); * const results = sorter.sort('john', ['name', 'email']); * ``` */ export declare class ObjectSorter { /** * The collection of objects to search through */ objectDictionary: T[]; /** * Creates a new ObjectSorter instance * * @param objectDictionaryArg - Array of objects to search through */ constructor(objectDictionaryArg?: T[]); /** * Searches and sorts objects based on how well they match the search string * in the specified object properties * * @param stringArg - The search query string * @param objectKeysArg - Object property names to search within, optionally weighted * @param optionsArg - Optional settings, such as `includeMatches` * @returns Array of results sorted by relevance (best matches first) * * @example * ```typescript * // Search for 'john' in both name and email fields * const results = sorter.sort('john', ['name', 'email']); * * // First result is the best match * console.log(results[0].item.name); // 'John Smith' * * // Rank name matches above email matches and report where each result matched * const weighted = sorter.sort('john', [{ name: 'name', weight: 2 }, 'email'], { includeMatches: true }); * console.log(weighted[0].matches?.[0].key); // 'name' * ``` */ sort(stringArg: string, objectKeysArg: TObjectSorterKey[], optionsArg?: IObjectSorterSortOptions): Array>; }