-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain.js.flow
44 lines (33 loc) · 1.17 KB
/
main.js.flow
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* @flow */
export type MatcherOptions = {
// Default: false
caseSensitive?: boolean,
// Default: infinite
maxResults?: number,
// Maximum gap to allow between consecutive letters in a match.
// Provide a smaller maxGap to speed up query results.
// Default: unlimited
maxGap?: number;
// Default: 1
numThreads?: number,
// Default: false
recordMatchIndexes?: boolean,
}
export type MatchResult = {
value: string,
// A number in the range (0-1]. Higher scores are more relevant.
// 0 denotes "no match" and will never be returned.
score: number,
// Matching character index in `value` for each character in `query`.
// This can be costly, so this is only returned if `recordMatchIndexes` was set in `options`.
matchIndexes?: Array<number>,
}
export class Matcher {
constructor(candidates: Array<string>) {}
// Returns all matching candidates (subject to `options`).
// Will be ordered by score, descending.
match: (query: string, options?: MatcherOptions) => Array<MatchResult>;
addCandidates: (candidates: Array<string>) => void;
removeCandidates: (candidates: Array<string>) => void;
setCandidates: (candidates: Array<string>) => void;
}