29 lines · 756 B · TypeScript
RawDownload
import { ClientSettingsSchema, type ClientSettings } from "@t3tools/contracts"; import { getLocalStorageItem, setLocalStorageItem } from "./hooks/useLocalStorage"; export const CLIENT_SETTINGS_STORAGE_KEY = "t3code:client-settings:v1"; function hasWindow(): boolean {  return typeof window !== "undefined";} export function readBrowserClientSettings(): ClientSettings | null {  if (!hasWindow()) {    return null;  }   try {    return getLocalStorageItem(CLIENT_SETTINGS_STORAGE_KEY, ClientSettingsSchema);  } catch {    return null;  }} export function writeBrowserClientSettings(settings: ClientSettings): void {  if (!hasWindow()) {    return;  }   setLocalStorageItem(CLIENT_SETTINGS_STORAGE_KEY, settings, ClientSettingsSchema);}