mirror of
https://github.com/DevJSTAR/JSTAR-Tab.git
synced 2025-04-18 17:35:26 +00:00
44 lines
1005 B
JavaScript
44 lines
1005 B
JavaScript
/**
|
|
* Storage utility object for managing localStorage operations
|
|
* All methods handle JSON parsing/stringifying and error cases
|
|
*/
|
|
const Storage = {
|
|
// Retrieve and parse stored value
|
|
get: (key) => {
|
|
try {
|
|
return JSON.parse(localStorage.getItem(key));
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
},
|
|
|
|
// Store value as JSON string
|
|
set: (key, value) => {
|
|
try {
|
|
localStorage.setItem(key, JSON.stringify(value));
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
},
|
|
|
|
// Delete specific key
|
|
remove: (key) => {
|
|
try {
|
|
localStorage.removeItem(key);
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
},
|
|
|
|
// Remove all stored data
|
|
clear: () => {
|
|
try {
|
|
localStorage.clear();
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
}; |