2021-07-13 05:35:31 +00:00
|
|
|
const prefix = "Props";
|
2021-07-10 02:47:40 +00:00
|
|
|
function put(key, value) {
|
|
|
|
if (value == null) return false;
|
|
|
|
try {
|
|
|
|
localStorage.setItem(prefix + ":" + key, JSON.stringify(value));
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get(key) {
|
|
|
|
if (!exists(key)) return null;
|
|
|
|
try {
|
|
|
|
return JSON.parse(localStorage.getItem(prefix + ":" + key));
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove(key) {
|
|
|
|
localStorage.removeItem(prefix + ":" + key);
|
|
|
|
}
|
|
|
|
|
|
|
|
function exists(key) {
|
|
|
|
return localStorage.getItem(prefix + ":" + key) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
export { put, get, remove, exists };
|