Skip to content

Commit c6b95df

Browse files
committed
fix: add types for the package
1 parent 94f6841 commit c6b95df

File tree

3 files changed

+79
-3
lines changed

3 files changed

+79
-3
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,23 @@ wrap("Hello world", "he")
9898

9999
### options
100100
In all the above functions, you can pass an optional object with the following keys
101-
* `maxResults` - The maximum numbers of results to return.
102-
* `usePathScoring`
103-
* `pathSeparator`
101+
```typescript
102+
{
103+
/** only for `filter` function */
104+
maxResults?: number
105+
106+
/** @default false */
107+
allowErrors?: boolean
108+
109+
/** @default true */
110+
usePathScoring?: boolean
111+
112+
/** @default false */
113+
useExtensionBonus?: boolean
114+
115+
pathSeparator?: '/' | '\\' | string
116+
}
117+
```
104118

105119
### New()
106120
Initializes the native binding

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.1",
44
"description": "Fuzzaldrin plus - fast using native c bindings",
55
"main": "fuzzaldrin-dist.js",
6+
"types": "./types/fuzzaldrin-plus-fast.d.ts",
67
"scripts": {
78
"native:clean": "shx rm -rf build prebuilds",
89
"native:build": "node-gyp-build",

types/fuzzaldrin-plus-fast.d.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)