|
| 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; |
0 commit comments