feat: active
This commit is contained in:
33
src/utils/storage.ts
Normal file
33
src/utils/storage.ts
Normal file
@ -0,0 +1,33 @@
|
||||
const NameSpace = 'ihealth-kit-registration_';
|
||||
|
||||
function getData<T>(key: string, defaultValue?: T): T | null {
|
||||
const rawData = window.localStorage.getItem(NameSpace + key);
|
||||
try {
|
||||
if (rawData) {
|
||||
return JSON.parse(rawData);
|
||||
} else {
|
||||
return defaultValue || null
|
||||
}
|
||||
} catch (e) {
|
||||
return defaultValue || null;
|
||||
}
|
||||
}
|
||||
|
||||
function setData<T>(key: string, data: T): void {
|
||||
window.localStorage.setItem(NameSpace + key, JSON.stringify(data));
|
||||
}
|
||||
|
||||
function clearData(key?: string): void {
|
||||
if (key) {
|
||||
window.localStorage.removeItem(NameSpace + key);
|
||||
} else {
|
||||
window.localStorage.clear()
|
||||
}
|
||||
}
|
||||
|
||||
const storage = {
|
||||
get: getData,
|
||||
set: setData,
|
||||
clear: clearData
|
||||
}
|
||||
export default storage
|
Reference in New Issue
Block a user