function stringify ( value ) { return JSON . stringify ( value ) ; } function parse < T > ( value ) { try { return JSON . parse ( value ) as T ; } catch ( error ) { return null ; } } interface ILocalStore { setValue ( key , data ) : ILocalStore ; getValue < T > ( key , defaultValue ? ) : T | null ; removeValue ( key ) : ILocalStore ; } const LocalStore = { setValue ( key , data ) { localStorage . setItem ( key , stringify ( data ) ) ; return this ; } , getValue < T > ( key , defaultValue ? ) { const value = localStorage . getItem ( key ) ; if ( ! value ) return defaultValue || null ; const data = parse < T > ( value ) ; return data ; } , removeValue ( key ) { localStorage . removeItem ( key ) ; return this ; } , } ; export default LocalStore ;