forked from kevinresol/react-native-default-preference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
56 lines (42 loc) · 1.48 KB
/
index.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
import { NativeModules } from 'react-native';
const { RNDefaultPreference } = NativeModules;
export interface RNDefaultPreferenceKeys {
[key: string]: string | number | boolean | string[] | null;
}
class DefaultPreference {
private static groupName: string = 'default';
static setName(name: string = 'default') {
DefaultPreference.groupName = name;
if (name !== 'default') {
RNDefaultPreference.setName(name);
}
}
static async get(key: string): Promise<string | number | boolean | null> {
return RNDefaultPreference.get(key);
}
static async set(key: string, value: string | number | boolean): Promise<void> {
return RNDefaultPreference.set(key, value);
}
static async clear(key: string): Promise<void> {
return RNDefaultPreference.clear(key);
}
static async getMultiple(keys: string[]): Promise<(string | number | boolean | null)[]> {
return RNDefaultPreference.getMultiple(keys);
}
static async setMultiple(data: RNDefaultPreferenceKeys): Promise<void> {
return RNDefaultPreference.setMultiple(data);
}
static async clearMultiple(keys: string[]): Promise<void> {
return RNDefaultPreference.clearMultiple(keys);
}
static async getAll(): Promise<RNDefaultPreferenceKeys> {
return RNDefaultPreference.getAll();
}
static async clearAll(): Promise<void> {
return RNDefaultPreference.clearAll();
}
static async getName(): Promise<string> {
return DefaultPreference.groupName;
}
}
export default DefaultPreference;