apkt-eis/src/utils/storage.ts
2024-02-19 09:08:50 +07:00

29 lines
765 B
TypeScript
Executable File

import { EncryptStorage } from 'encrypt-storage'
const encryptStorage = new EncryptStorage('qwertyuiopasdfghjklzxcvbnm-1234567890')
const writeData = (key: string, data: any) => encryptStorage.setItem(key, data)
const writeDataJson = (key: string, data: any) => encryptStorage.setItem(key, JSON.stringify(data))
const removeData = (key: string) => encryptStorage.removeItem(key)
const readData = (key: string) => {
try {
return encryptStorage.getItem(key)
} catch (error) {
return undefined
}
}
const readDataJson = (key: string) => {
try {
return encryptStorage.getItem(key)
} catch (error) {
return undefined
}
}
export {
removeData,
writeData,
writeDataJson,
readData,
readDataJson
}