/local-storage

A wrapper of localStorage in order to support expiration time and asynchronous execution.

Primary LanguageJavaScriptMIT LicenseMIT

local-storage

A wrapper of localStorage in order to support expiration time and asynchronous execution.

methods

clear() asynchronous
localStore.clear();
setItem(key, data, expires, onerror) asynchronous
// store data for an hour.
localStore.setItem('testKey', {name: 'yannxiao'}, 1000 * 60 * 60, function(err) {
    if (err.name === 'QuotaExceededError') {
        // todo sth when exceeded the quota.
    }
});

// same as native
localStore.setItem('testKey', {name: 'yannxiao'}, function(err) {
    if (err.name === 'QuotaExceededError') {
        // todo sth when exceeded the quota.
    }
});
getItem(key, callback) asynchronous
localStore.getItem('testKey', function(data) {
    // to do sth.
});
removeItem(key) asynchronous
localStore.removeItem('testKey1 testKey2');
key(nth) synchronous
var key = localStore.key(0);
getLength() synchronous
var len = localStore.getLength();