const safeParse = (value: string | null): T | null => { if (!value) return null; try { return JSON.parse(value) as T; } catch { return null; } }; export const localStorageAdapter = { read(key: string): T | null { return safeParse(localStorage.getItem(key)); }, write(key: string, value: T) { localStorage.setItem(key, JSON.stringify(value)); }, readString(key: string): string | null { return localStorage.getItem(key); }, writeString(key: string, value: string) { localStorage.setItem(key, value); }, remove(key: string) { localStorage.removeItem(key); }, };