-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
export interface IOptions { | ||
|
||
/** @default false */ | ||
allowErrors?: boolean | ||
|
||
/** @default true */ | ||
usePathScoring?: boolean | ||
|
||
/** @default false */ | ||
useExtensionBonus?: boolean | ||
|
||
pathSeparator?: '/' | '\\' | string | ||
|
||
// TODO not implemented? | ||
// optCharRegEx?: RegExp | ||
|
||
// TODO not implemented? | ||
// wrap?: { tagOpen?: string; tagClass?: string; tagClose?: string } | ||
|
||
/** @deprecated: there is no major benefit by precomputing something just for the query. */ | ||
preparedQuery?: {} | ||
} | ||
|
||
export type IFilterOptions<T> = IOptions & { | ||
|
||
// TODO not implemented? | ||
// key?: T extends string ? never : keyof T | ||
|
||
/** The maximum numbers of results to return */ | ||
maxResults?: number | ||
|
||
// TODO not implemented | ||
// maxInners?: number | ||
} | ||
|
||
/** Sort and filter the given candidates by matching them against the given query. | ||
* @param candidates An array of strings or objects. | ||
* @param query A string query to match each candidate against. | ||
* @return returns an array of candidates sorted by best match against the query. | ||
*/ | ||
export function filter<T>( | ||
data: T[], | ||
query: string, | ||
options?: IFilterOptions<T> | ||
): T[] | ||
|
||
/** Score the given string against the given query. | ||
* @param str The string the score. | ||
* @param query The query to score the string against. | ||
* @param options options | ||
*/ | ||
export function score(str: string, query: string, options?: IOptions): number | ||
|
||
/** Gives an array of indices at which the query matches the given string */ | ||
export function match(str: string, query: string, options?: IOptions): number[] | ||
|
||
/** Gives an HTML/Markdown string that highlights the range for which the match happens */ | ||
export function wrap(str: string, query: string, options?: IOptions): string | ||
|
||
/** @deprecated: there is no major benefit by precomputing something just for the query. */ | ||
export function prepareQuery(query: string, options?: IOptions): {} |