src/index.js
/**
 * do something with localstorage on init
 */
do something with localstorage on init
do something with localstorage on init
function initAdapter() {
    if (!options.cache) {
        adapter = options.adapter;
        return;
    }
    try {
        if (typeof localStorage !== 'undefined') {
            localStorage.setItem('test', 't');
            localStorage.removeItem('test');
        }
    } catch (e) {
        adapter = options.adapter;
        return;
    }
    adapter = cacheAdapter;
    K_LAST_MODIFIED = `${options.name}_config_last_modified`;
    K_URL_PREFIX = `${options.name}_url_`;
    const V_LAST_MODIFIED = localStorage.getItem(K_LAST_MODIFIED);
    const expiredTime = parseInt(V_LAST_MODIFIED, 10) + options.maxAge;
    if (expiredTime < new Date().getTime()) {
        clearStorage();
    }
}
function initAdapter ( ) { if ( ! options . cache ) { adapter = options . adapter ; return ; } try { if ( typeof localStorage !== 'undefined' ) { localStorage . setItem ( 'test' , 't' ) ; localStorage . removeItem ( 'test' ) ; } } catch ( e ) { adapter = options . adapter ; return ; } adapter = cacheAdapter ; K_LAST_MODIFIED = ` ${ options . name } ` ; K_URL_PREFIX = ` ${ options . name } ` ; const V_LAST_MODIFIED = localStorage . getItem ( K_LAST_MODIFIED ) ; const expiredTime = parseInt ( V_LAST_MODIFIED , 10 ) + options . maxAge ; if ( expiredTime < new Date ( ) . getTime ( ) ) { clearStorage ( ) ; } }
do something with localstorage on init
do something with localstorage on init
// clear all data if expired