You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
664 B
43 lines
664 B
3 years ago
|
function localStorage() {
|
||
|
return window.localStorage;
|
||
|
}
|
||
|
|
||
|
function get(key) {
|
||
|
return JSON.parse(localStorage().getItem(key));
|
||
|
}
|
||
|
|
||
|
function set(key, data) {
|
||
|
return localStorage().setItem(key, JSON.stringify(data));
|
||
|
}
|
||
|
|
||
|
function all() {
|
||
|
const data = {};
|
||
|
for (var i = localStorage().length - 1; i >= 0; i--) {
|
||
|
var key = localStorage().key(i);
|
||
|
data[key] = get(key);
|
||
|
}
|
||
|
|
||
|
return data;
|
||
|
}
|
||
|
|
||
|
function remove(key) {
|
||
|
return localStorage().removeItem(key);
|
||
|
}
|
||
|
|
||
|
function clearAll() {
|
||
|
return localStorage().clear();
|
||
|
}
|
||
|
|
||
|
function has(key) {
|
||
|
return localStorage().getItem(key) !== null;
|
||
|
}
|
||
|
|
||
|
export default {
|
||
|
get,
|
||
|
set,
|
||
|
all,
|
||
|
remove,
|
||
|
clearAll,
|
||
|
has
|
||
|
};
|