@mdn/bob
Version:
Builder of Bits aka The MDN Web Docs interactive examples, example builder
25 lines • 726 B
JavaScript
/**
* Adds key & value to {@link localStorage}, without throwing an exception when it is unavailable
*/
export function storeItem(key, value) {
try {
localStorage.setItem(key, value);
}
catch (err) {
console.warn(`Unable to write ${key} to localStorage`, err);
}
}
/**
* @returns the value of a given key from {@link localStorage}, or null when the key wasn't found.
* It doesn't throw an exception when {@link localStorage} is unavailable
*/
export function getStorageItem(key) {
try {
return localStorage.getItem(key);
}
catch (err) {
console.warn(`Unable to read ${key} from localStorage`, err);
return null;
}
}
//# sourceMappingURL=utils.js.map