UNPKG

1.76 kBTypeScriptView Raw
1import * as fuzzy from 'fuzzy';
2export declare class FuzzySearch {
3 private static readonly PRE;
4 private static readonly POST;
5 /**
6 * Filters the input and returns with an array that contains all items that match the pattern.
7 */
8 filter<T>(input: FuzzySearch.Input<T>): Promise<FuzzySearch.Match<T>[]>;
9 protected sortResults<T>(left: fuzzy.FilterResult<T>, right: fuzzy.FilterResult<T>): number;
10 protected mapResult<T>(result: fuzzy.FilterResult<T>): FuzzySearch.Match<T>;
11 protected mapRanges(input: string): ReadonlyArray<FuzzySearch.Range>;
12}
13/**
14 * Fuzzy searcher.
15 */
16export declare namespace FuzzySearch {
17 /**
18 * A range representing the match region.
19 */
20 interface Range {
21 /**
22 * The zero based offset of the match region.
23 */
24 readonly offset: number;
25 /**
26 * The length of the match region.
27 */
28 readonly length: number;
29 }
30 /**
31 * A fuzzy search match.
32 */
33 interface Match<T> {
34 /**
35 * The original item.
36 */
37 readonly item: T;
38 /**
39 * An array of ranges representing the match regions.
40 */
41 readonly ranges: ReadonlyArray<Range>;
42 }
43 /**
44 * The fuzzy search input.
45 */
46 interface Input<T> {
47 /**
48 * The pattern to match.
49 */
50 readonly pattern: string;
51 /**
52 * The items to filter based on the `pattern`.
53 */
54 readonly items: ReadonlyArray<T>;
55 /**
56 * Function that extracts the string from the inputs which will be used to evaluate the fuzzy matching filter.
57 */
58 readonly transform: (item: T) => string;
59 }
60}
61//# sourceMappingURL=fuzzy-search.d.ts.map
\No newline at end of file