UNPKG

3.61 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
43interface LocalForageDriverSupportFunc {
44 (): Promise<boolean>;
45}
46
47interface LocalForageDriver extends LocalForageDbMethods {
48 _driver: string;
49
50 _initStorage(options: LocalForageOptions): void;
51
52 _support?: boolean | LocalForageDriverSupportFunc;
53}
54
55interface LocalForageSerializer {
56 serialize<T>(value: T | ArrayBuffer | Blob, callback: (value: string, error: any) => void): void;
57
58 deserialize<T>(value: string): T | ArrayBuffer | Blob;
59
60 stringToBuffer(serializedString: string): ArrayBuffer;
61
62 bufferToString(buffer: ArrayBuffer): string;
63}
64
65interface LocalForage extends LocalForageDbMethods {
66 LOCALSTORAGE: string;
67 WEBSQL: string;
68 INDEXEDDB: string;
69
70 /**
71 * 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.
72 * If you set any config values with this method they will persist after driver changes, so you can call config() then setDriver()
73 * @param {LocalForageOptions} options?
74 */
75 config(options: LocalForageOptions): boolean;
76 config(options: string): any;
77 config(): LocalForageOptions;
78
79 /**
80 * Create a new instance of localForage to point to a different store.
81 * All the configuration options used by config are supported.
82 * @param {LocalForageOptions} options
83 */
84 createInstance(options: LocalForageOptions): LocalForage;
85
86 driver(): string;
87 /**
88 * Force usage of a particular driver or drivers, if available.
89 * @param {string} driver
90 */
91 setDriver(driver: string | string[]): Promise<void>;
92 setDriver(driver: string | string[], callback: () => void, errorCallback: (error: any) => void): void;
93
94 defineDriver(driver: LocalForageDriver): Promise<void>;
95 defineDriver(driver: LocalForageDriver, callback: () => void, errorCallback: (error: any) => void): void;
96 /**
97 * Return a particular driver
98 * @param {string} driver
99 */
100 getDriver(driver: string): Promise<LocalForageDriver>;
101
102 getSerializer(): Promise<LocalForageSerializer>;
103 getSerializer(callback: (serializer: LocalForageSerializer) => void): void;
104
105 supports(driverName: string): boolean;
106
107 ready(callback: (error: any) => void): void;
108 ready(): Promise<void>;
109}
110
111declare module "localforage" {
112 let localforage: LocalForage;
113 export = localforage;
114}
115
\No newline at end of file