MCPcopy Create free account
hub / github.com/bytebase/bytebase / safeReadJSON

Function safeReadJSON

frontend/src/views/sql-editor/Sheet/context.ts:242–254  ·  view source on GitHub ↗
(
  key: string,
  parse: (raw: unknown) => T | undefined
)

Source from the content-addressed store, hash-verified

240// ---- localStorage persistence ----------------------------------------------
241
242const safeReadJSON = <T>(
243 key: string,
244 parse: (raw: unknown) => T | undefined
245): T | undefined => {
246 if (typeof window === "undefined") return undefined;
247 try {
248 const raw = window.localStorage.getItem(key);
249 if (raw === null) return undefined;
250 return parse(JSON.parse(raw));
251 } catch {
252 return undefined;
253 }
254};
255
256const safeWriteJSON = (key: string, value: unknown) => {
257 if (typeof window === "undefined") return;

Callers 1

reloadFromStorageFunction · 0.85

Calls 1

parseFunction · 0.85

Tested by

no test coverage detected