bingo / src /lib /storage.ts
smf2010's picture
Duplicate from hf4all/bingo
e7c4a86
raw
history blame contribute delete
No virus
632 Bytes
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();
}
}