var _local = {
set(key, value, expires) {
let params = { key, value, expires };
if (expires) {
var data = Object.assign(params, { startTime: new Date().getTime() });
localStorage.setItem(key, JSON.stringify(data));
} else {
if (Object.prototype.toString.call(value) == '[object Object]') {
value = JSON.stringify(value);
}
if (Object.prototype.toString.call(value) == '[object Array]') {
value = JSON.stringify(value);
}
localStorage.setItem(key, value);
}
},
get(key) {
let item = localStorage.getItem(key);
try {
item = JSON.parse(item);
} catch (error) {
item = item;
}
if (item && item.startTime) {
let date = new Date().getTime();
if (date - item.startTime > item.expires) {
localStorage.removeItem(name);
return false;
} else {
return item.value;
}
} else {
return item;
}
},
remove(key) {
localStorage.removeItem(key);
},
clear() {
localStorage.clear();
}
}
var _session = {
get: function (key) {
var data = sessionStorage[key];
if (!data || data === "null") {
return null;
}
return JSON.parse(data).value;
},
set: function (key, value) {
var data = {
value: value
}
sessionStorage[key] = JSON.stringify(data);
},
remove(key) {
sessionStorage.removeItem(key);
},
clear() {
sessionStorage.clear();
}
}
export { _local, _session }