Files
suwayomi-material-you-webui/webUI/react/src/util/storage.tsx

23 lines
595 B
TypeScript
Raw Normal View History

2021-03-07 16:27:13 +03:30
function getItem<T>(key: string, defaultValue: T) : T {
try {
const item = window.localStorage.getItem(key);
if (item !== null) { return JSON.parse(item); }
window.localStorage.setItem(key, JSON.stringify(defaultValue));
} finally {
// eslint-disable-next-line no-unsafe-finally
return defaultValue;
}
}
function setItem<T>(key: string, value: T): void {
try {
window.localStorage.setItem(key, JSON.stringify(value));
// eslint-disable-next-line no-empty
} catch (error) { }
}
export default { getItem, setItem };