Skip to content

Commit 2d9d5e9

Browse files
committed
add type defs for lite commonjs
1 parent 6cdb437 commit 2d9d5e9

File tree

3 files changed

+358
-4
lines changed

3 files changed

+358
-4
lines changed

lite/fuzzball_lite.d.ts

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
export interface FuzzballBaseOptions {
2+
/**
3+
* Use Intl.Collator for locale-sensitive string comparison
4+
*/
5+
useCollator?: boolean;
6+
/**
7+
* Apply basic cleanup, non-alphanumeric to whitespace etc. if true. default true
8+
*/
9+
full_process?: boolean;
10+
/**
11+
* 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
12+
*/
13+
force_ascii?: boolean;
14+
/**
15+
* Collapse consecutive white space during full_process, default true
16+
*/
17+
collapseWhitespace?: boolean;
18+
/**
19+
* Substitution cost, default 1 for distance, 2 for all ratios, prob don't want to change it
20+
*/
21+
wildcards?: string;
22+
/**
23+
* Use astral symbol and post-BMP codepoint aware distance calculation, default false
24+
*/
25+
astral?: boolean;
26+
/**
27+
* Normalize unicode representations, default true when astral is true
28+
*/
29+
normalize?: boolean;
30+
}
31+
32+
export interface FuzzballTokenSetOptions extends FuzzballBaseOptions {
33+
/**
34+
* Include ratio as part of token set test suite
35+
*/
36+
trySimple?: boolean;
37+
}
38+
39+
interface FuzzballExtractBaseOptions extends FuzzballBaseOptions {
40+
/**
41+
* Include ratio as part of token set test suite
42+
*/
43+
trySimple?: boolean;
44+
/**
45+
* Scoring function, default: ratio
46+
*/
47+
scorer?: (str1: any, str2: any, opts?: FuzzballExtractOptions) => number;
48+
/**
49+
* Function that will be run on each choice (but not the query) before scoring
50+
*/
51+
processor?: (str: any) => any;
52+
/**
53+
* Max number of results to return
54+
*/
55+
limit?: number;
56+
/**
57+
* Lowest score to return, default 0
58+
*/
59+
cutoff?: number;
60+
}
61+
62+
interface CancellationToken {
63+
/**
64+
* If extract has been canceled;
65+
*/
66+
canceled?: boolean;
67+
}
68+
69+
export interface FuzzballExtractOptions extends FuzzballExtractBaseOptions {
70+
/**
71+
* Return array of objects instead of tuples
72+
*/
73+
returnObjects?: false;
74+
}
75+
76+
export interface FuzzballExtractObjectOptions extends FuzzballExtractBaseOptions {
77+
/**
78+
* Return array of objects instead of tuples
79+
*/
80+
returnObjects: true;
81+
}
82+
83+
export interface FuzzballAsyncExtractOptions extends FuzzballExtractOptions {
84+
/**
85+
* Track if extract has been canceled
86+
*/
87+
cancelToken?: CancellationToken;
88+
/**
89+
* Number of loop iterations between each async iteration
90+
*/
91+
asyncLoopOffset?: number;
92+
}
93+
94+
export interface FuzzballAsyncExtractObjectOptions extends FuzzballExtractObjectOptions {
95+
/**
96+
* Track if extract has been canceled;
97+
*/
98+
cancelToken?: CancellationToken;
99+
/**
100+
* Number of loop iterations between each async iteration
101+
*/
102+
asyncLoopOffset?: number;
103+
}
104+
105+
export interface FuzzballDedupeOptions extends FuzzballExtractOptions {
106+
/**
107+
* Keep the items and scores mapped to this value, default false
108+
*/
109+
keepmap?: false;
110+
/**
111+
* Function that will be run on each item before scoring
112+
*/
113+
processor?: (str: any) => string;
114+
}
115+
116+
export interface FuzzballDedupeOptionsWithMap extends FuzzballExtractOptions {
117+
/**
118+
* Keep the items and scores mapped to this value, default false
119+
*/
120+
keepmap: true;
121+
/**
122+
* Function that will be run on each item before scoring
123+
*/
124+
processor?: (str: any) => string;
125+
}
126+
127+
export interface FuzzballDedupeObjOptions extends FuzzballExtractObjectOptions {
128+
/**
129+
* Keep the items and scores mapped to this value, default false
130+
*/
131+
keepmap?: false;
132+
/**
133+
* Function that will be run on each item before scoring
134+
*/
135+
processor?: (str: any) => string;
136+
}
137+
138+
export interface FuzzballDedupeObjOptionsWithMap extends FuzzballExtractObjectOptions {
139+
/**
140+
* Keep the items and scores mapped to this value, default false
141+
*/
142+
keepmap: true;
143+
/**
144+
* Function that will be run on each item before scoring
145+
*/
146+
processor?: (str: any) => string;
147+
}
148+
149+
export function distance(str1: string, str2: string, opts?: FuzzballBaseOptions): number;
150+
export function ratio(str1: string, str2: string, opts?: FuzzballBaseOptions): number;
151+
export function token_set_ratio(str1: string, str2: string, opts?: FuzzballTokenSetOptions): number;
152+
export function token_sort_ratio(str1: string, str2: string, opts?: FuzzballBaseOptions): number;
153+
export function token_similarity_sort_ratio(str1: string, str2: string, opts?: FuzzballTokenSetOptions): number;
154+
export function full_process(str: string, options?: FuzzballExtractOptions | boolean): string;
155+
export function process_and_sort(str: string): string;
156+
export function unique_tokens(str: string, opts?: FuzzballExtractOptions): string[];
157+
158+
export function extract(query: any, choices: any[], opts?: FuzzballExtractOptions): Array<[any, number, number]>;
159+
export function extract(query: any, choices: Object, opts?: FuzzballExtractOptions): Array<[any, number, string]>;
160+
export function extract(query: any, choices: any[], opts?: FuzzballExtractObjectOptions): Array<{choice: any, score: number, key: number}>;
161+
export function extract(query: any, choices: Object, opts?: FuzzballExtractObjectOptions): Array<{ choice: any, score: number, key: string}>;
162+
163+
export function extractAsync(query: any, choices: any[], opts: FuzzballAsyncExtractOptions, callback: (err: any, results?: Array<[any, number, number]>) => void): void;
164+
export function extractAsync(query: any, choices: Object, opts: FuzzballAsyncExtractOptions, callback: (err: any, results?: Array<[any, number, string]>) => void): void;
165+
export function extractAsync(query: any, choices: any[], opts: FuzzballAsyncExtractObjectOptions, callback: (err: any, results?: Array<{ choice: any, score: number, key: number }>) => void): void;
166+
export function extractAsync(query: any, choices: Object, opts: FuzzballAsyncExtractObjectOptions, callback: (err: any, results?: Array<{ choice: any, score: number, key: string }>) => void): void;
167+
168+
export function extractAsPromised(query: any, choices: any[], opts: FuzzballAsyncExtractOptions): Promise<Array<[any, number, number]>>;
169+
export function extractAsPromised(query: any, choices: Object, opts: FuzzballAsyncExtractOptions): Promise<Array<[any, number, string]>>;
170+
export function extractAsPromised(query: any, choices: any[], opts: FuzzballAsyncExtractObjectOptions): Promise<Array<{ choice: any, score: number, key: number }>>;
171+
export function extractAsPromised(query: any, choices: Object, opts: FuzzballAsyncExtractObjectOptions): Promise<Array<{ choice: any, score: number, key: string }>>;
172+
173+
export function dedupe(contains_dupes: any[], opts?: FuzzballDedupeOptions): Array<[any, number]>;
174+
export function dedupe(contains_dupes: Object, opts?: FuzzballDedupeOptions): Array<[any, string]>;
175+
export function dedupe(contains_dupes: any[], opts?: FuzzballDedupeOptionsWithMap): Array<[any, number, Array<[any, number, number]>]>;
176+
export function dedupe(contains_dupes: Object, opts?: FuzzballDedupeOptionsWithMap): Array<[any, string, Array<[any, number, string]>]>;
177+
178+
export function dedupe(contains_dupes: any[], opts?: FuzzballDedupeObjOptions): Array<{item: any, key: number}>;
179+
export function dedupe(contains_dupes: Object, opts?: FuzzballDedupeObjOptions): Array<{ item: any, key: string }>;
180+
export function dedupe(contains_dupes: any[], opts?: FuzzballDedupeObjOptionsWithMap): Array<{item: any, key: number, matches: Array<{ choice: any, score: number, key: number }>}>;
181+
export function dedupe(contains_dupes: Object, opts?: FuzzballDedupeObjOptionsWithMap): Array<{item: any, key: string, matches: Array<{ choice: any, score: number, key: string }>}>;
182+
183+
export as namespace fuzzball;

ultra_lite/esm/fuzzball_ultra_lite.esm.min.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ export interface FuzzballTokenSetOptions extends FuzzballBaseOptions {
2626
* Include ratio as part of token set test suite
2727
*/
2828
trySimple?: boolean;
29-
/**
30-
* Sort tokens by by similarity to each other before combining instead of alphabetically
31-
*/
32-
sortBySimilarity?: boolean
3329
}
3430

3531
interface FuzzballExtractBaseOptions extends FuzzballBaseOptions {
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
export interface FuzzballBaseOptions {
2+
/**
3+
* Apply basic cleanup, non-alphanumeric to whitespace etc. if true. default true
4+
*/
5+
full_process?: boolean;
6+
/**
7+
* 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
8+
*/
9+
force_ascii?: boolean;
10+
/**
11+
* Collapse consecutive white space during full_process, default true
12+
*/
13+
collapseWhitespace?: boolean;
14+
/**
15+
* Substitution cost, default 1 for distance, 2 for all ratios, prob don't want to change it
16+
*/
17+
wildcards?: string;
18+
/**
19+
* Normalize unicode representations, default true when astral is true
20+
*/
21+
normalize?: boolean;
22+
}
23+
24+
export interface FuzzballTokenSetOptions extends FuzzballBaseOptions {
25+
/**
26+
* Include ratio as part of token set test suite
27+
*/
28+
trySimple?: boolean;
29+
}
30+
31+
interface FuzzballExtractBaseOptions extends FuzzballBaseOptions {
32+
/**
33+
* Include ratio as part of token set test suite
34+
*/
35+
trySimple?: boolean;
36+
/**
37+
* Scoring function, default: ratio
38+
*/
39+
scorer?: (str1: any, str2: any, opts?: FuzzballExtractOptions) => number;
40+
/**
41+
* Function that will be run on each choice (but not the query) before scoring
42+
*/
43+
processor?: (str: any) => any;
44+
/**
45+
* Max number of results to return
46+
*/
47+
limit?: number;
48+
/**
49+
* Lowest score to return, default 0
50+
*/
51+
cutoff?: number;
52+
}
53+
54+
interface CancellationToken {
55+
/**
56+
* If extract has been canceled;
57+
*/
58+
canceled?: boolean;
59+
}
60+
61+
export interface FuzzballExtractOptions extends FuzzballExtractBaseOptions {
62+
/**
63+
* Return array of objects instead of tuples
64+
*/
65+
returnObjects?: false;
66+
}
67+
68+
export interface FuzzballExtractObjectOptions extends FuzzballExtractBaseOptions {
69+
/**
70+
* Return array of objects instead of tuples
71+
*/
72+
returnObjects: true;
73+
}
74+
75+
export interface FuzzballAsyncExtractOptions extends FuzzballExtractOptions {
76+
/**
77+
* Track if extract has been canceled
78+
*/
79+
cancelToken?: CancellationToken;
80+
/**
81+
* Number of loop iterations between each async iteration
82+
*/
83+
asyncLoopOffset?: number;
84+
}
85+
86+
export interface FuzzballAsyncExtractObjectOptions extends FuzzballExtractObjectOptions {
87+
/**
88+
* Track if extract has been canceled;
89+
*/
90+
cancelToken?: CancellationToken;
91+
/**
92+
* Number of loop iterations between each async iteration
93+
*/
94+
asyncLoopOffset?: number;
95+
}
96+
97+
export interface FuzzballDedupeOptions extends FuzzballExtractOptions {
98+
/**
99+
* Keep the items and scores mapped to this value, default false
100+
*/
101+
keepmap?: false;
102+
/**
103+
* Function that will be run on each item before scoring
104+
*/
105+
processor?: (str: any) => string;
106+
}
107+
108+
export interface FuzzballDedupeOptionsWithMap extends FuzzballExtractOptions {
109+
/**
110+
* Keep the items and scores mapped to this value, default false
111+
*/
112+
keepmap: true;
113+
/**
114+
* Function that will be run on each item before scoring
115+
*/
116+
processor?: (str: any) => string;
117+
}
118+
119+
export interface FuzzballDedupeObjOptions extends FuzzballExtractObjectOptions {
120+
/**
121+
* Keep the items and scores mapped to this value, default false
122+
*/
123+
keepmap?: false;
124+
/**
125+
* Function that will be run on each item before scoring
126+
*/
127+
processor?: (str: any) => string;
128+
}
129+
130+
export interface FuzzballDedupeObjOptionsWithMap extends FuzzballExtractObjectOptions {
131+
/**
132+
* Keep the items and scores mapped to this value, default false
133+
*/
134+
keepmap: true;
135+
/**
136+
* Function that will be run on each item before scoring
137+
*/
138+
processor?: (str: any) => string;
139+
}
140+
141+
export function distance(str1: string, str2: string, opts?: FuzzballBaseOptions): number;
142+
export function ratio(str1: string, str2: string, opts?: FuzzballBaseOptions): number;
143+
export function token_set_ratio(str1: string, str2: string, opts?: FuzzballTokenSetOptions): number;
144+
export function token_sort_ratio(str1: string, str2: string, opts?: FuzzballBaseOptions): number;
145+
export function token_similarity_sort_ratio(str1: string, str2: string, opts?: FuzzballTokenSetOptions): number;
146+
export function full_process(str: string, options?: FuzzballExtractOptions | boolean): string;
147+
export function process_and_sort(str: string): string;
148+
export function unique_tokens(str: string, opts?: FuzzballExtractOptions): string[];
149+
150+
export function extract(query: any, choices: any[], opts?: FuzzballExtractOptions): Array<[any, number, number]>;
151+
export function extract(query: any, choices: Object, opts?: FuzzballExtractOptions): Array<[any, number, string]>;
152+
export function extract(query: any, choices: any[], opts?: FuzzballExtractObjectOptions): Array<{choice: any, score: number, key: number}>;
153+
export function extract(query: any, choices: Object, opts?: FuzzballExtractObjectOptions): Array<{ choice: any, score: number, key: string}>;
154+
155+
export function extractAsync(query: any, choices: any[], opts: FuzzballAsyncExtractOptions, callback: (err: any, results?: Array<[any, number, number]>) => void): void;
156+
export function extractAsync(query: any, choices: Object, opts: FuzzballAsyncExtractOptions, callback: (err: any, results?: Array<[any, number, string]>) => void): void;
157+
export function extractAsync(query: any, choices: any[], opts: FuzzballAsyncExtractObjectOptions, callback: (err: any, results?: Array<{ choice: any, score: number, key: number }>) => void): void;
158+
export function extractAsync(query: any, choices: Object, opts: FuzzballAsyncExtractObjectOptions, callback: (err: any, results?: Array<{ choice: any, score: number, key: string }>) => void): void;
159+
160+
export function extractAsPromised(query: any, choices: any[], opts: FuzzballAsyncExtractOptions): Promise<Array<[any, number, number]>>;
161+
export function extractAsPromised(query: any, choices: Object, opts: FuzzballAsyncExtractOptions): Promise<Array<[any, number, string]>>;
162+
export function extractAsPromised(query: any, choices: any[], opts: FuzzballAsyncExtractObjectOptions): Promise<Array<{ choice: any, score: number, key: number }>>;
163+
export function extractAsPromised(query: any, choices: Object, opts: FuzzballAsyncExtractObjectOptions): Promise<Array<{ choice: any, score: number, key: string }>>;
164+
165+
export function dedupe(contains_dupes: any[], opts?: FuzzballDedupeOptions): Array<[any, number]>;
166+
export function dedupe(contains_dupes: Object, opts?: FuzzballDedupeOptions): Array<[any, string]>;
167+
export function dedupe(contains_dupes: any[], opts?: FuzzballDedupeOptionsWithMap): Array<[any, number, Array<[any, number, number]>]>;
168+
export function dedupe(contains_dupes: Object, opts?: FuzzballDedupeOptionsWithMap): Array<[any, string, Array<[any, number, string]>]>;
169+
170+
export function dedupe(contains_dupes: any[], opts?: FuzzballDedupeObjOptions): Array<{item: any, key: number}>;
171+
export function dedupe(contains_dupes: Object, opts?: FuzzballDedupeObjOptions): Array<{ item: any, key: string }>;
172+
export function dedupe(contains_dupes: any[], opts?: FuzzballDedupeObjOptionsWithMap): Array<{item: any, key: number, matches: Array<{ choice: any, score: number, key: number }>}>;
173+
export function dedupe(contains_dupes: Object, opts?: FuzzballDedupeObjOptionsWithMap): Array<{item: any, key: string, matches: Array<{ choice: any, score: number, key: string }>}>;
174+
175+
export as namespace fuzzball;

0 commit comments

Comments
 (0)