2021-03-26 04:17:02 +04:30
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
2021-03-07 22:25:29 +03:30
|
|
|
* 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/. */
|
|
|
|
|
|
2023-02-06 10:06:33 +01:00
|
|
|
function getItem<T>(key: string, defaultValue: T): T {
|
2023-05-11 18:00:37 +02:00
|
|
|
const item = window.localStorage.getItem(key);
|
2021-03-07 16:27:13 +03:30
|
|
|
|
2023-05-11 18:00:37 +02:00
|
|
|
if (item !== null) {
|
|
|
|
|
return JSON.parse(item);
|
2023-02-06 10:06:33 +01:00
|
|
|
}
|
2023-05-11 18:00:37 +02:00
|
|
|
|
|
|
|
|
window.localStorage.setItem(key, JSON.stringify(defaultValue));
|
2021-03-07 22:25:29 +03:30
|
|
|
return defaultValue;
|
2021-03-07 16:27:13 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setItem<T>(key: string, value: T): void {
|
2023-05-11 18:00:37 +02:00
|
|
|
window.localStorage.setItem(key, JSON.stringify(value));
|
2021-03-07 16:27:13 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default { getItem, setItem };
|