1
0

synchronize localStorage properties to preference profile

This commit is contained in:
Hazelnoot
2025-06-01 13:15:12 -04:00
parent c1af8dfb7f
commit 3d3846ec85
6 changed files with 105 additions and 49 deletions
+5 -5
View File
@@ -48,23 +48,23 @@ export type Keys = (
//const safeSessionStorage = new Map<Keys, string>();
export const miLocalStorage = {
getItem: (key: Keys): string | null => {
return window.localStorage.getItem(key);
getItem: <T extends string = string>(key: Keys): T | null => {
return window.localStorage.getItem(key) as T | null;
},
setItem: (key: Keys, value: string): void => {
setItem: <T extends string = string>(key: Keys, value: T): void => {
window.localStorage.setItem(key, value);
},
removeItem: (key: Keys): void => {
window.localStorage.removeItem(key);
},
getItemAsJson: (key: Keys): any | undefined => {
getItemAsJson: <T = any>(key: Keys): T | undefined => {
const item = miLocalStorage.getItem(key);
if (item === null) {
return undefined;
}
return JSON.parse(item);
},
setItemAsJson: (key: Keys, value: any): void => {
setItemAsJson: <T = any>(key: Keys, value: T): void => {
miLocalStorage.setItem(key, JSON.stringify(value));
},
};