const KEY = 'accessmate_prefs'; export function load(): Record { try { // JSON.parse happily accepts any valid JSON value, not just objects — 'null', // '5', and '"x"' all parse without throwing, so a malformed/corrupted stored // value (or one written by a future/different format) can come back as null // or a primitive instead of an object, crashing every caller that assigns a // property onto it. const parsed: unknown = JSON.parse(localStorage.getItem(KEY) ?? '{}'); return (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) ? parsed as Record : {}; } catch (_e) { return {}; } } export function save(prefs: Record): void { try { localStorage.setItem(KEY, JSON.stringify(prefs)); } catch (_e) { // localStorage unavailable (private browsing, storage full, etc.) } }