|
| 1 | +export interface IOptions { |
| 2 | + |
| 3 | + /** @default false */ |
| 4 | + allowErrors?: boolean |
| 5 | + |
| 6 | + /** @default true */ |
| 7 | + usePathScoring?: boolean |
| 8 | + |
| 9 | + /** @default false */ |
| 10 | + useExtensionBonus?: boolean |
| 11 | + |
| 12 | + pathSeparator?: '/' | '\\' | string |
| 13 | + |
| 14 | + // TODO not implemented? |
| 15 | + // optCharRegEx?: RegExp |
| 16 | + |
| 17 | + // TODO not implemented? |
| 18 | + // wrap?: { tagOpen?: string; tagClass?: string; tagClose?: string } |
| 19 | + |
| 20 | + /** @deprecated: there is no major benefit by precomputing something just for the query. */ |
| 21 | + preparedQuery?: {} |
| 22 | +} |
| 23 | + |
| 24 | +export type IFilterOptions<T> = IOptions & { |
| 25 | + |
| 26 | + // TODO not implemented? |
| 27 | + // key?: T extends string ? never : keyof T |
| 28 | + |
| 29 | + /** The maximum numbers of results to return */ |
| 30 | + maxResults?: number |
| 31 | + |
| 32 | + // TODO not implemented |
| 33 | + // maxInners?: number |
| 34 | +} |
| 35 | + |
| 36 | +/** Sort and filter the given candidates by matching them against the given query. |
| 37 | +* @param candidates An array of strings or objects. |
| 38 | +* @param query A string query to match each candidate against. |
| 39 | +* @return returns an array of candidates sorted by best match against the query. |
| 40 | + */ |
| 41 | +export function filter<T>( |
| 42 | + data: T[], |
| 43 | + query: string, |
| 44 | + options?: IFilterOptions<T> |
| 45 | +): T[] |
| 46 | + |
| 47 | +/** Score the given string against the given query. |
| 48 | +* @param str The string the score. |
| 49 | +* @param query The query to score the string against. |
| 50 | +* @param options options |
| 51 | +*/ |
| 52 | +export function score(str: string, query: string, options?: IOptions): number |
| 53 | + |
| 54 | +/** Gives an array of indices at which the query matches the given string */ |
| 55 | +export function match(str: string, query: string, options?: IOptions): number[] |
| 56 | + |
| 57 | +/** Gives an HTML/Markdown string that highlights the range for which the match happens */ |
| 58 | +export function wrap(str: string, query: string, options?: IOptions): string |
| 59 | + |
| 60 | +/** @deprecated: there is no major benefit by precomputing something just for the query. */ |
| 61 | +export function prepareQuery(query: string, options?: IOptions): {} |
0 commit comments