-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathfuzzball.d.ts
211 lines (192 loc) · 8.53 KB
/
fuzzball.d.ts
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
export interface FuzzballBaseOptions {
/**
* Use Intl.Collator for locale-sensitive string comparison
*/
useCollator?: boolean;
/**
* Apply basic cleanup, non-alphanumeric to whitespace etc. if true. default true
*/
full_process?: boolean;
/**
* Strip non-ascii in full_process if true (non-ascii will not become whtespace), only applied if full_process is true as well, default true
*/
force_ascii?: boolean;
/**
* Collapse consecutive white space during full_process, default true
*/
collapseWhitespace?: boolean;
/**
* Substitution cost, default 1 for distance, 2 for all ratios, prob don't want to change it
*/
wildcards?: string;
/**
* Use astral symbol and post-BMP codepoint aware distance calculation, default false
*/
astral?: boolean;
/**
* Normalize unicode representations, default true when astral is true
*/
normalize?: boolean;
}
export interface FuzzballTokenSetOptions extends FuzzballBaseOptions {
/**
* Include ratio as part of token set test suite
*/
trySimple?: boolean;
/**
* Sort tokens by by similarity to each other before combining instead of alphabetically
*/
sortBySimilarity?: boolean
}
interface FuzzballExtractBaseOptions extends FuzzballBaseOptions {
/**
* Include ratio as part of token set test suite
*/
trySimple?: boolean;
/**
* Scoring function, default: ratio
*/
scorer?: (str1: any, str2: any, opts?: FuzzballExtractOptions) => number;
/**
* Function that will be run on each choice (but not the query) before scoring
*/
processor?: (str: any) => any;
/**
* Max number of results to return
*/
limit?: number;
/**
* Lowest score to return, default 0
*/
cutoff?: number;
/**
* Sort tokens by similarity before combining with token set scorers
*/
sortBySimilarity?: boolean
}
interface AbortController {
/**
* If extract has been aborted;
*/
signal: { aborted: boolean }
}
interface CancellationToken {
/**
* If extract has been canceled;
*/
canceled?: boolean;
}
export interface FuzzballExtractOptions extends FuzzballExtractBaseOptions {
/**
* Return array of objects instead of tuples
*/
returnObjects?: false;
}
export interface FuzzballExtractObjectOptions extends FuzzballExtractBaseOptions {
/**
* Return array of objects instead of tuples
*/
returnObjects: true;
}
export interface FuzzballAsyncExtractOptions extends FuzzballExtractOptions {
/**
* Track if extract has been aborted
*/
abortController?: AbortController;
/**
* Track if extract has been canceled
*/
cancelToken?: CancellationToken;
/**
* Number of loop iterations between each async iteration
*/
asyncLoopOffset?: number;
}
export interface FuzzballAsyncExtractObjectOptions extends FuzzballExtractObjectOptions {
/**
* Track if extract has been aborted
*/
abortController?: AbortController;
/**
* Track if extract has been canceled;
*/
cancelToken?: CancellationToken;
/**
* Number of loop iterations between each async iteration
*/
asyncLoopOffset?: number;
}
export interface FuzzballDedupeOptions extends FuzzballExtractOptions {
/**
* Keep the items and scores mapped to this value, default false
*/
keepmap?: false;
/**
* Function that will be run on each item before scoring
*/
processor?: (str: any) => string;
}
export interface FuzzballDedupeOptionsWithMap extends FuzzballExtractOptions {
/**
* Keep the items and scores mapped to this value, default false
*/
keepmap: true;
/**
* Function that will be run on each item before scoring
*/
processor?: (str: any) => string;
}
export interface FuzzballDedupeObjOptions extends FuzzballExtractObjectOptions {
/**
* Keep the items and scores mapped to this value, default false
*/
keepmap?: false;
/**
* Function that will be run on each item before scoring
*/
processor?: (str: any) => string;
}
export interface FuzzballDedupeObjOptionsWithMap extends FuzzballExtractObjectOptions {
/**
* Keep the items and scores mapped to this value, default false
*/
keepmap: true;
/**
* Function that will be run on each item before scoring
*/
processor?: (str: any) => string;
}
export function distance(str1: string, str2: string, opts?: FuzzballBaseOptions): number;
export function ratio(str1: string, str2: string, opts?: FuzzballBaseOptions): number;
export function partial_ratio(str1: string, str2: string, opts?: FuzzballBaseOptions): number;
export function token_set_ratio(str1: string, str2: string, opts?: FuzzballTokenSetOptions): number;
export function token_sort_ratio(str1: string, str2: string, opts?: FuzzballBaseOptions): number;
export function token_similarity_sort_ratio(str1: string, str2: string, opts?: FuzzballTokenSetOptions): number;
export function partial_token_set_ratio(str1: string, str2: string, opts?: FuzzballTokenSetOptions): number;
export function partial_token_sort_ratio(str1: string, str2: string, opts?: FuzzballBaseOptions): number;
export function partial_token_similarity_sort_ratio(str1: string, str2: string, opts?: FuzzballTokenSetOptions): number;
export function WRatio(str1: string, str2: string, opts?: FuzzballTokenSetOptions): number;
export function full_process(str: string, options?: FuzzballExtractOptions | boolean): string;
export function process_and_sort(str: string): string;
export function unique_tokens(str: string, opts?: FuzzballExtractOptions): string[];
export function extract(query: any, choices: any[], opts?: FuzzballExtractOptions): Array<[any, number, number]>;
export function extract(query: any, choices: Object, opts?: FuzzballExtractOptions): Array<[any, number, string]>;
export function extract(query: any, choices: any[], opts?: FuzzballExtractObjectOptions): Array<{choice: any, score: number, key: number}>;
export function extract(query: any, choices: Object, opts?: FuzzballExtractObjectOptions): Array<{ choice: any, score: number, key: string}>;
export function extractAsync(query: any, choices: any[], opts: FuzzballAsyncExtractOptions, callback: (err: any, results?: Array<[any, number, number]>) => void): void;
export function extractAsync(query: any, choices: Object, opts: FuzzballAsyncExtractOptions, callback: (err: any, results?: Array<[any, number, string]>) => void): void;
export function extractAsync(query: any, choices: any[], opts: FuzzballAsyncExtractObjectOptions, callback: (err: any, results?: Array<{ choice: any, score: number, key: number }>) => void): void;
export function extractAsync(query: any, choices: Object, opts: FuzzballAsyncExtractObjectOptions, callback: (err: any, results?: Array<{ choice: any, score: number, key: string }>) => void): void;
export function extractAsPromised(query: any, choices: any[], opts: FuzzballAsyncExtractOptions): Promise<Array<[any, number, number]>>;
export function extractAsPromised(query: any, choices: Object, opts: FuzzballAsyncExtractOptions): Promise<Array<[any, number, string]>>;
export function extractAsPromised(query: any, choices: any[], opts: FuzzballAsyncExtractObjectOptions): Promise<Array<{ choice: any, score: number, key: number }>>;
export function extractAsPromised(query: any, choices: Object, opts: FuzzballAsyncExtractObjectOptions): Promise<Array<{ choice: any, score: number, key: string }>>;
export function dedupe(contains_dupes: any[], opts?: FuzzballDedupeOptions): Array<[any, number]>;
export function dedupe(contains_dupes: Object, opts?: FuzzballDedupeOptions): Array<[any, string]>;
export function dedupe(contains_dupes: any[], opts?: FuzzballDedupeOptionsWithMap): Array<[any, number, Array<[any, number, number]>]>;
export function dedupe(contains_dupes: Object, opts?: FuzzballDedupeOptionsWithMap): Array<[any, string, Array<[any, number, string]>]>;
export function dedupe(contains_dupes: any[], opts?: FuzzballDedupeObjOptions): Array<{item: any, key: number}>;
export function dedupe(contains_dupes: Object, opts?: FuzzballDedupeObjOptions): Array<{ item: any, key: string }>;
export function dedupe(contains_dupes: any[], opts?: FuzzballDedupeObjOptionsWithMap): Array<{item: any, key: number, matches: Array<{ choice: any, score: number, key: number }>}>;
export function dedupe(contains_dupes: Object, opts?: FuzzballDedupeObjOptionsWithMap): Array<{item: any, key: string, matches: Array<{ choice: any, score: number, key: string }>}>;
export as namespace fuzzball;