Files
suwayomi-material-you-webui/src/util/localStorage.tsx

25 lines
688 B
TypeScript
Raw Normal View History

/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
function getItem<T>(key: string, defaultValue: T): T {
const item = window.localStorage.getItem(key);
2021-03-07 16:27:13 +03:30
if (item !== null) {
return JSON.parse(item);
}
window.localStorage.setItem(key, JSON.stringify(defaultValue));
return defaultValue;
2021-03-07 16:27:13 +03:30
}
function setItem<T>(key: string, value: T): void {
window.localStorage.setItem(key, JSON.stringify(value));
2021-03-07 16:27:13 +03:30
}
export default { getItem, setItem };