Skip to content

Commit

Permalink
fix: add types for the package
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Oct 29, 2020
1 parent 94f6841 commit c6b95df
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,23 @@ wrap("Hello world", "he")

### options
In all the above functions, you can pass an optional object with the following keys
* `maxResults` - The maximum numbers of results to return.
* `usePathScoring`
* `pathSeparator`
```typescript
{
/** only for `filter` function */
maxResults?: number

/** @default false */
allowErrors?: boolean

/** @default true */
usePathScoring?: boolean

/** @default false */
useExtensionBonus?: boolean

pathSeparator?: '/' | '\\' | string
}
```

### New()
Initializes the native binding
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.1",
"description": "Fuzzaldrin plus - fast using native c bindings",
"main": "fuzzaldrin-dist.js",
"types": "./types/fuzzaldrin-plus-fast.d.ts",
"scripts": {
"native:clean": "shx rm -rf build prebuilds",
"native:build": "node-gyp-build",
Expand Down
61 changes: 61 additions & 0 deletions types/fuzzaldrin-plus-fast.d.ts
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): {}

0 comments on commit c6b95df

Please sign in to comment.