forked from planttheidea/micro-memoize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
58 lines (46 loc) · 1.47 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
type Dictionary<Type> = {
[key: string]: Type;
[index: number]: Type;
};
export declare namespace MicroMemoize {
export type Key = any[];
export type Value = any;
export type RawKey = Key | IArguments;
export type Cache = import('./src/Cache').Cache;
export type EqualityComparator = (object1: any, object2: any) => boolean;
export type MatchingKeyComparator = (key1: Key, key2: RawKey) => boolean;
export type CacheModifiedHandler = (
cache: Cache,
options: NormalizedOptions,
memoized: Function,
) => void;
export type KeyTransformer = (args: Key) => Key;
export type KeyIndexGetter = (keyToMatch: RawKey) => number;
export type StandardOptions = {
isEqual?: EqualityComparator;
isMatchingKey?: MatchingKeyComparator;
isPromise?: boolean;
maxSize?: number;
onCacheAdd?: CacheModifiedHandler;
onCacheChange?: CacheModifiedHandler;
onCacheHit?: CacheModifiedHandler;
transformKey?: KeyTransformer;
};
export type Options = StandardOptions & Dictionary<any>;
export type NormalizedOptions = Options & {
isEqual: EqualityComparator;
isPromise: boolean;
maxSize: number;
};
export type Memoized<Fn extends Function> = Fn &
Dictionary<any> & {
cache: Cache;
fn: Fn;
isMemoized: true;
options: NormalizedOptions;
};
}
export default function memoize<Fn extends Function>(
fn: Fn | MicroMemoize.Memoized<Fn>,
options?: MicroMemoize.Options,
): MicroMemoize.Memoized<Fn>;