import { Dictionary } from '@nx-mean-starter/models' ; export class LocalStorage { private fallbackStorage : Dictionary = { } ; keys ( ) { try { return Object . keys ( window . localStorage ) ; } catch ( e ) { return Object . keys ( this . fallbackStorage ) ; } } getItem < T > ( key ) { try { let value = window . localStorage . getItem ( key ) ; try { value = JSON . parse ( value ) ; } catch { } return value as any ; } catch ( e ) { return this . fallbackStorage [ key ] ; } } setItem ( key , input ) { const value = input instanceof Object ? JSON . stringify ( input ) : input ; try { window . localStorage . setItem ( key , value ) ; } catch ( e ) { this . fallbackStorage [ key ] = value ; } } removeItem ( key ) { try { return window . localStorage . removeItem ( key ) ; } catch ( e ) { delete this . fallbackStorage [ key ] ; } } clear ( ) { try { window . localStorage . clear ( ) ; } catch ( e ) { this . fallbackStorage = { } ; } } }