forked from mixmaxhq/frecency
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
39 lines (34 loc) · 1.29 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Type definitions for @getstation/frecency 1.4
// Project: https://github.com/getstation/frecency
// TypeScript Version: 3.9
declare module '@getstation/frecency' {
export type idAttrFn = (result: string) => string;
export type StorageProvider = {
getItem: (key: string) => string | null;
setItem: (key: string, value: string) => void;
removeItem: (key: string) => void;
};
export type FrecencySelectionPayload = { selectedId: string; dateSelection?: Date; searchQuery?: string };
export default class Frecency<T = any> {
constructor(constructOpts: {
key: string;
idAttribute?: string | idAttrFn;
timeStampsLimit?: number;
recentSelectionsLimit?: number;
storageProvider?: StorageProvider;
exactQueryMatchWeight?: number;
subQueryMatchWeight?: number;
recentSelectionsMatchWeight?: number;
});
save: (params: FrecencySelectionPayload) => void;
saveItems: (params: FrecencySelectionPayload[]) => void;
sort:
| ((params: { searchQuery: string; results: T[] }) => T[])
| ((params: {
searchQuery: string;
results: T[];
keepScores?: boolean;
}) => Array<T & { _frecencyScore?: number }>);
computeScore: (params: { searchQuery: string; item: T; now?: number }) => number;
}
}