File size: 632 Bytes
e7c4a86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { getMany, set, del, clear } from 'idb-keyval';

export const Storage = {
  async get(key: string | string[] | null): Promise<any> {
    if (key === null) return null;
    if (typeof key === 'string') {
      key = [key]
    }
    const returnData: Record<string, any> = {}
    const values = await getMany(key)
    key.forEach((k, idx)=> {
      returnData[k] = values[idx]
    })
    return returnData;
  },
  async set(object: any) {
    for (let key of Object.keys(object)) {
      await set(key, object[key])
    }
  },
  async remove(key: string) {
    return del(key);
  },
  async clear() {
    return clear();
  }
}