MCPcopy
hub / github.com/simstudioai/sim / getItem

Method getItem

apps/sim/lib/core/utils/browser-storage.ts:21–41  ·  view source on GitHub ↗

* Safely gets an item from localStorage * @param key - The storage key * @param defaultValue - The default value to return if key doesn't exist or access fails * @returns The stored value or default value

(key: string, defaultValue: T)

Source from the content-addressed store, hash-verified

19 * @returns The stored value or default value
20 */
21 static getItem<T = string>(key: string, defaultValue: T): T {
22 if (typeof window === 'undefined') {
23 return defaultValue
24 }
25
26 try {
27 const item = window.localStorage.getItem(key)
28 if (item === null) {
29 return defaultValue
30 }
31
32 try {
33 return JSON.parse(item) as T
34 } catch {
35 return item as T
36 }
37 } catch (error) {
38 logger.warn(`Failed to get localStorage item "${key}":`, error)
39 return defaultValue
40 }
41 }
42
43 /**
44 * Safely sets an item in localStorage

Callers 15

store.tsFile · 0.80
migrateFromLocalStorageFunction · 0.80
loadExecutionPointerFunction · 0.80
store.tsFile · 0.80
readOAuthReturnContextFunction · 0.80
syncThemeToNextThemesFunction · 0.80
getThemeFromNextThemesFunction · 0.80
getAllMethod · 0.80
consumeMethod · 0.80

Calls 2

parseMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected