class Storage { static readonly prefix : string = '__' ; static readonly splitCode : string = '|_|' ; static readonly storage = localStorage || window . localStorage ; static readonly defaultExpiredTime = 30 * 24 * 60 * 60 * 1000 ; private prefix : string ; private splitCode : string ; constructor ( prefix ? , splitCode ? ) { this . prefix = prefix || Storage . prefix ; this . splitCode = splitCode || Storage . splitCode ; } param key private getStorageKey ( key ) { return `${ this . prefix }${ key }` ; } param key param value param expired public setItem ( key , value , expired = Storage . defaultExpiredTime ) { const itemKey = this . getStorageKey ( key ) ; const date = new Date ( ) ; const expiredTimestamp = date . getTime ( ) + expired ; Storage . storage . setItem ( itemKey , `${ expiredTimestamp }${ this . splitCode }${ value }` ) ; } param key public getItem ( key ) { const itemKey = this . getStorageKey ( key ) ; const value = Storage . storage . getItem ( itemKey ) ; if ( value ) { const localValueSplits = value . split ( this . splitCode ) ; const currentTimestamp = ( new Date ( ) ) . getTime ( ) ; if ( + localValueSplits [ 0 ] > + ( new Date ( ) ) ) { return localValueSplits [ 1 ] ; } this . removeItem ( key ) ; } return null ; } param key public removeItem ( key ) { const itemKey = this . getStorageKey ( key ) ; Storage . storage . removeItem ( itemKey ) ; } } export default Storage ;