let storage ; try { storage = { getItem : localStorage . getItem . bind ( localStorage ) , setItem : localStorage . setItem . bind ( localStorage ) } ; } catch ( error ) { console . warn ( `LocalStorage not available, falling back to in-memory storage: ${ error }` ) ; const cache = new Map < string , string > ( ) ; storage = { getItem ( key ) { return cache . get ( key ) || null ; } , setItem ( key , value ) { cache . set ( key , value ) ; } } ; } export const getItem = ( key ) : any => { const value = storage . getItem ( key ) ; try { return value ? JSON . parse ( value ) : undefined ; } catch ( e ) { console . warn ( `Ignoring malformed value: ${ value }` ) ; return undefined ; } } ; export const setItem = ( key , value ) : void => { storage . setItem ( key , JSON . stringify ( value ) ) ; } ;