Harrison Deng
57f67391f1
After reconsidering where I want to take this project, I realized that a MPA is more fitting.
32 lines
686 B
JavaScript
32 lines
686 B
JavaScript
const prefix = "Props";
|
|
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 };
|