mirror of
https://github.com/brianlovin/security-checklist.git
synced 2026-03-11 08:55:31 +00:00
33 lines
No EOL
711 B
JavaScript
33 lines
No EOL
711 B
JavaScript
export const getItemFromStorage = key => {
|
|
if (!localStorage) return;
|
|
|
|
try {
|
|
return JSON.parse(localStorage.getItem(key) || false);
|
|
} catch (err) {}
|
|
};
|
|
|
|
export const storeItem = (key, value) => {
|
|
if (!localStorage) return;
|
|
|
|
try {
|
|
localStorage.setItem(key, JSON.stringify(value));
|
|
window.dispatchEvent(new Event('storage:updated'));
|
|
} catch (err) {}
|
|
};
|
|
|
|
export const removeItemFromStorage = key => {
|
|
if (!localStorage) return;
|
|
|
|
try {
|
|
localStorage.removeItem(key);
|
|
window.dispatchEvent(new Event('storage:updated'));
|
|
} catch (err) {}
|
|
};
|
|
|
|
export const getLocalStorageLength = () => {
|
|
if (!localStorage) return;
|
|
|
|
try {
|
|
return localStorage.length;
|
|
} catch (err) {}
|
|
} |