1 | type KeyAttributes = {
|
2 | threshold?: Ranking;
|
3 | maxRanking: Ranking;
|
4 | minRanking: Ranking;
|
5 | };
|
6 | interface RankingInfo {
|
7 | rankedValue: string;
|
8 | rank: Ranking;
|
9 | keyIndex: number;
|
10 | keyThreshold: Ranking | undefined;
|
11 | }
|
12 | interface ValueGetterKey<ItemType> {
|
13 | (item: ItemType): string | Array<string>;
|
14 | }
|
15 | interface IndexedItem<ItemType> {
|
16 | item: ItemType;
|
17 | index: number;
|
18 | }
|
19 | interface RankedItem<ItemType> extends RankingInfo, IndexedItem<ItemType> {
|
20 | }
|
21 | interface BaseSorter<ItemType> {
|
22 | (a: RankedItem<ItemType>, b: RankedItem<ItemType>): number;
|
23 | }
|
24 | interface Sorter<ItemType> {
|
25 | (matchItems: Array<RankedItem<ItemType>>): Array<RankedItem<ItemType>>;
|
26 | }
|
27 | interface KeyAttributesOptions<ItemType> {
|
28 | key?: string | ValueGetterKey<ItemType>;
|
29 | threshold?: Ranking;
|
30 | maxRanking?: Ranking;
|
31 | minRanking?: Ranking;
|
32 | }
|
33 | type KeyOption<ItemType> = KeyAttributesOptions<ItemType> | ValueGetterKey<ItemType> | string;
|
34 | interface MatchSorterOptions<ItemType = unknown> {
|
35 | keys?: ReadonlyArray<KeyOption<ItemType>>;
|
36 | threshold?: Ranking;
|
37 | baseSort?: BaseSorter<ItemType>;
|
38 | keepDiacritics?: boolean;
|
39 | sorter?: Sorter<ItemType>;
|
40 | }
|
41 | declare const rankings: {
|
42 | readonly CASE_SENSITIVE_EQUAL: 7;
|
43 | readonly EQUAL: 6;
|
44 | readonly STARTS_WITH: 5;
|
45 | readonly WORD_STARTS_WITH: 4;
|
46 | readonly CONTAINS: 3;
|
47 | readonly ACRONYM: 2;
|
48 | readonly MATCHES: 1;
|
49 | readonly NO_MATCH: 0;
|
50 | };
|
51 | type Ranking = typeof rankings[keyof typeof rankings];
|
52 | declare const defaultBaseSortFn: BaseSorter<unknown>;
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | declare function matchSorter<ItemType = string>(items: ReadonlyArray<ItemType>, value: string, options?: MatchSorterOptions<ItemType>): Array<ItemType>;
|
61 | declare namespace matchSorter {
|
62 | var rankings: {
|
63 | readonly CASE_SENSITIVE_EQUAL: 7;
|
64 | readonly EQUAL: 6;
|
65 | readonly STARTS_WITH: 5;
|
66 | readonly WORD_STARTS_WITH: 4;
|
67 | readonly CONTAINS: 3;
|
68 | readonly ACRONYM: 2;
|
69 | readonly MATCHES: 1;
|
70 | readonly NO_MATCH: 0;
|
71 | };
|
72 | }
|
73 | export { matchSorter, rankings, defaultBaseSortFn };
|
74 | export type { MatchSorterOptions, KeyAttributesOptions, KeyOption, KeyAttributes, RankingInfo, ValueGetterKey, };
|