import { getGlobalObject } from './misc' ; const global = getGlobalObject ( ) ; export function setStorage ( key , value , expire ? ) { const curTime = new global . Date ( ) . getTime ( ) ; const val = JSON . stringify ( { data : value , time : curTime , expire } ) ; global . localStorage . setItem ( key , val ) ; } export function getStorage ( key ) { const value = global . localStorage . getItem ( key ) ; if ( ! value ) { return false ; } const { data , time = 0 , expire = 0 } = JSON . parse ( value ) ; if ( expire === 0 ) { return data ; } if ( expire > 0 && new global . Date ( ) . getTime ( ) - time > expire ) { global . localStorage . removeItem ( key ) ; return false ; } return data ; }