-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstorages.ts
36 lines (28 loc) · 934 Bytes
/
storages.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
// utils/storages.ts
const namespace = 'baicizhan-helper'
function get(arg: string | string[]) {
return Array.isArray(arg) ? getMulit(arg) : getSingle(arg)
}
function getSingle(key: string) {
const completeKey = `local:${namespace}.${key}`
return storage.getItem(completeKey)
}
function getMulit(keys: string[]) {
const completeKeys = keys.map(key => `local:${namespace}.${key}`)
return storage.getItems(completeKeys)
}
function set(key: string, value: unknown) {
const completeKey = `local:${namespace}.${key}`
// if (typeof value === 'object') {
// value = JSON.stringify(value)
// }
return storage.setItem(completeKey, value)
}
function remove(keys: string[]) {
const completeKeys = keys.map(key => `local:${namespace}.${key}`)
return storage.removeItems(completeKeys)
}
// alias
const getStorageInfo = get
const storageModule = { set, get, getStorageInfo, remove }
export default storageModule