UNPKG

@jsonhero/fuzzy-json-search

Version:
80 lines (79 loc) 2.7 kB
import { IItemAccessor } from "./scoring"; export declare type Match = { start: number; end: number; }; export declare type ItemScore = { /** * Overall score. */ score: number; label?: string; /** * Matches within the label. */ labelMatch?: Match[]; description?: string; descriptionMatch?: Match[]; rawValue?: string; /** * Matches within the rawValue. * Only available if the item has a rawValue. * * @see JsonItem.rawValue */ rawValueMatch?: Match[]; formattedValue?: string; /** * Matches within the formattedValue. * Only available if the item has a formattedValue. * * @see JsonItem.formattedValue */ formattedValueMatch?: Match[]; }; export declare type PreparedQueryPiece = { /** * The original query as provided as input. */ original: string; originalLowercase: string; /** * Normalizes paths and removes wildcards * from the query. * * So if the query is `"foo/bar"`, the normalized * query is `foo.bar`. */ pathNormalized: string; /** * In addition to the normalized path, will have * whitespace and wildcards removed. */ normalized: string; normalizedLowercase: string; /** * The query is wrapped in quotes which means * this query must be a substring of the input. * In other words, no fuzzy matching is used. */ expectContiguousMatch: boolean; }; export declare type PreparedQuery = PreparedQueryPiece & { /** * Query split by spaces into pieces. */ values: PreparedQueryPiece[] | undefined; /** * Whether the query contains path separator(s) or not. */ containsPathSeparator: boolean; }; export { FuzzyScore, IItemAccessor, scoreFuzzy } from "./scoring"; export declare function prepareQuery(original: string): PreparedQuery; export declare function stripWildcards(pattern: string): string; export declare function scoreItemFuzzy<T>(item: T, query: PreparedQuery, allowNonContiguousMatches: boolean, accessor: IItemAccessor<T>, cache?: Map<number, ItemScore>): ItemScore; export declare function compareItemsByFuzzyScore<T>(itemA: T, itemB: T, query: PreparedQuery, allowNonContiguousMatches: boolean, accessor: IItemAccessor<T>, cache?: Map<number, ItemScore>): number; export declare function compareAnything(one: string, other: string, lookFor: string): number; export declare function compareByPrefix(one: string, other: string, lookFor: string): number; export declare function normalizeMatches(matches: Match[]): Match[];