import { ExpiredUnit , StorageUtil , isBrowser } from './util' ; interface ICache { [ key ] : boolean ; } const cache = { } ; function WebStorage ( storage , key ? , expiredAt = 0 , expiredUnit = 'd' ) { return ( target , propertyName ) : void => { key = key || propertyName ; Object . defineProperty ( target , propertyName , { get : ( ) => { return StorageUtil . get ( storage , key as string ) ; } , set : ( value ) => { if ( ! cache [ key as string ] ) { const storedValue = StorageUtil . get ( storage , key as string ) ; if ( storedValue === null ) { StorageUtil . set ( storage , key as string , value , expiredAt , expiredUnit ) ; } cache [ key as string ] = true ; return ; } StorageUtil . set ( storage , key as string , value , expiredAt , expiredUnit ) ; } , enumerable : true , configurable : true , } ) ; } ; } param expiredAt param expiredUnit export function LocalStorage ( key ? , expiredAt = 0 , expiredUnit = 't' ) { return WebStorage ( isBrowser ? localStorage : null , key , expiredAt , expiredUnit ) ; } param expiredAt param expiredUnit export function SessionStorage ( key ? , expiredAt = 0 , expiredUnit = 't' ) { return WebStorage ( isBrowser ? sessionStorage : null , key , expiredAt , expiredUnit ) ; }