UNPKG

3.78 kBTypeScriptView Raw
1
2interface LocalForageOptions {
3 driver?: string | string[];
4
5 name?: string;
6
7 size?: number;
8
9 storeName?: string;
10
11 version?: number;
12
13 description?: string;
14}
15
16interface LocalForageDbMethods {
17 getItem<T>(key: string): Promise<T>;
18 getItem<T>(key: string, callback: (err: any, value: T) => void): void;
19
20 setItem<T>(key: string, value: T): Promise<T>;
21 setItem<T>(key: string, value: T, callback: (err: any, value: T) => void): void;
22
23 removeItem(key: string): Promise<void>;
24 removeItem(key: string, callback: (err: any) => void): void;
25
26 clear(): Promise<void>;
27 clear(callback: (err: any) => void): void;
28
29 length(): Promise<number>;
30 length(callback: (err: any, numberOfKeys: number) => void): void;
31
32 key(keyIndex: number): Promise<string>;
33 key(keyIndex: number, callback: (err: any, key: string) => void): void;
34
35 keys(): Promise<string[]>;
36 keys(callback: (err: any, keys: string[]) => void): void;
37
38 iterate<T, U>(iteratee: (value: T, key: string, iterationNumber: number) => U): Promise<U>;
39 iterate<T, U>(iteratee: (value: T, key: string, iterationNumber: number) => U,
40 callback: (err: any, result: U) => void): void;
41
42 dropInstance(callback?: (err: any) => void): Promise<void>;
43 dropInstance(dbInstanceOptions?: LocalForageOptions, callback?: (err: any) => void): Promise<void>;
44}
45
46interface LocalForageDriverSupportFunc {
47 (): Promise<boolean>;
48}
49
50interface LocalForageDriver extends LocalForageDbMethods {
51 _driver: string;
52
53 _initStorage(options: LocalForageOptions): void;
54
55 _support?: boolean | LocalForageDriverSupportFunc;
56}
57
58interface LocalForageSerializer {
59 serialize<T>(value: T | ArrayBuffer | Blob, callback: (value: string, error: any) => void): void;
60
61 deserialize<T>(value: string): T | ArrayBuffer | Blob;
62
63 stringToBuffer(serializedString: string): ArrayBuffer;
64
65 bufferToString(buffer: ArrayBuffer): string;
66}
67
68interface LocalForage extends LocalForageDbMethods {
69 LOCALSTORAGE: string;
70 WEBSQL: string;
71 INDEXEDDB: string;
72
73 /**
74 * Set and persist localForage options. This must be called before any other calls to localForage are made, but can be called after localForage is loaded.
75 * If you set any config values with this method they will persist after driver changes, so you can call config() then setDriver()
76 * @param {LocalForageOptions} options?
77 */
78 config(options: LocalForageOptions): boolean;
79 config(options: string): any;
80 config(): LocalForageOptions;
81
82 /**
83 * Create a new instance of localForage to point to a different store.
84 * All the configuration options used by config are supported.
85 * @param {LocalForageOptions} options
86 */
87 createInstance(options: LocalForageOptions): LocalForage;
88
89 driver(): string;
90 /**
91 * Force usage of a particular driver or drivers, if available.
92 * @param {string} driver
93 */
94 setDriver(driver: string | string[]): Promise<void>;
95 setDriver(driver: string | string[], callback: () => void, errorCallback: (error: any) => void): void;
96
97 defineDriver(driver: LocalForageDriver): Promise<void>;
98 defineDriver(driver: LocalForageDriver, callback: () => void, errorCallback: (error: any) => void): void;
99 /**
100 * Return a particular driver
101 * @param {string} driver
102 */
103 getDriver(driver: string): Promise<LocalForageDriver>;
104
105 getSerializer(): Promise<LocalForageSerializer>;
106 getSerializer(callback: (serializer: LocalForageSerializer) => void): void;
107
108 supports(driverName: string): boolean;
109
110 ready(callback: (error: any) => void): void;
111 ready(): Promise<void>;
112}
113
114declare module "localforage" {
115 let localforage: LocalForage;
116 export = localforage;
117}
118
\No newline at end of file