17 lines
710 B
TypeScript
17 lines
710 B
TypeScript
/** localStorage / sessionStorage wrappers: storage can be blocked, so every access is try/catch. */
|
|
export function lsGet(key: string): string | null {
|
|
try { return window.localStorage.getItem(key); } catch { return null; }
|
|
}
|
|
export function lsSet(key: string, value: string): void {
|
|
try { window.localStorage.setItem(key, value); } catch { /* ignore */ }
|
|
}
|
|
export function ssGet(key: string): string | null {
|
|
try { return window.sessionStorage.getItem(key); } catch { return null; }
|
|
}
|
|
export function ssSet(key: string, value: string | null): void {
|
|
try {
|
|
if (value === null) window.sessionStorage.removeItem(key);
|
|
else window.sessionStorage.setItem(key, value);
|
|
} catch { /* ignore */ }
|
|
}
|