class InMemoryStorage implements Storage { storage : { [ key ] : string ; } = { } ; clear = ( ) : void => { this . storage = { } ; } ; getItem = ( name ) : string | null => { if ( Object . prototype . hasOwnProperty . call ( this . storage , name ) ) { return this . storage [ name ] ; } return null ; } ; key = ( index ) : string | null => { return Object . keys ( this . storage ) [ index ] || null ; } ; removeItem = ( name ) : void => { delete this . storage [ name ] ; } ; setItem = ( name , value ) : void => { this . storage [ name ] = String ( value ) ; } ; get length ( ) : number { return Object . keys ( this . storage ) . length ; } } export function storageFactory ( getStorage ) { try { const storage = getStorage ( ) ; const testKey = '__some_random_key_you_are_not_going_to_use__' ; storage . setItem ( testKey , testKey ) ; storage . removeItem ( testKey ) ; return storage ; } catch ( e ) { return new InMemoryStorage ( ) ; } }