forked from obytes/react-native-template-obytes
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreact-native-mmkv.ts
More file actions
37 lines (35 loc) · 1.16 KB
/
react-native-mmkv.ts
File metadata and controls
37 lines (35 loc) · 1.16 KB
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
const sharedMockStorage = new Map<string, string>();
const createMockStorage = () => ({
getString: (key: string): string | undefined => sharedMockStorage.get(key),
set: (key: string, value: string): void => {
sharedMockStorage.set(key, value);
},
remove: (key: string): void => {
sharedMockStorage.delete(key);
},
clearAll: (): void => {
sharedMockStorage.clear();
},
getAllKeys: (): Array<string> => Array.from(sharedMockStorage.keys()),
contains: (key: string): boolean => sharedMockStorage.has(key),
getNumber: (key: string): number | undefined => {
const value = sharedMockStorage.get(key);
return value ? Number(value) : undefined;
},
getBoolean: (key: string): boolean | undefined => {
const value = sharedMockStorage.get(key);
if (value === undefined) {
return undefined;
}
return value === 'true';
},
setNumber: (key: string, value: number): void => {
sharedMockStorage.set(key, String(value));
},
setBoolean: (key: string, value: boolean): void => {
sharedMockStorage.set(key, String(value));
},
});
export function createMMKV(_options?: { id?: string }) {
return createMockStorage();
}