class MockedLocalStorage { private storage = new Map < string , string > ( ) ; getItem ( key ) { const _key = String ( key ) ; if ( this . storage . has ( _key ) ) { this . storage . get ( _key ) as string ; } return null ; } key ( index ) { if ( index < 0 || index >= this . length ) { return null ; } let i = 0 ; for ( const value of this . storage . values ( ) ) { if ( i === index ) { return value ; } i += 1 ; } return null ; } setItem ( key , value ) { this . storage . set ( String ( key ) , String ( value ) ) ; } removeItem ( key ) { this . storage . delete ( String ( key ) ) ; } clear ( ) { this . storage . clear ( ) ; } get length ( ) { return this . storage . size ; } } const localStorage = typeof window === 'undefined' ? new MockedLocalStorage ( ) : window . localStorage ; export default localStorage ;