Skip to content

Instantly share code, notes, and snippets.

@justmarkup
Created January 2, 2015 15:08
Show Gist options
  • Save justmarkup/c1c9da55d4c84fcca084 to your computer and use it in GitHub Desktop.
Save justmarkup/c1c9da55d4c84fcca084 to your computer and use it in GitHub Desktop.
basket
remove: function( key ) {
try {
localStorage.removeItem( storagePrefix + key );
return this;
} catch( e ) {
return false;
}
},
get: function( key ) {
try {
var item = localStorage.getItem( storagePrefix + key );
return JSON.parse( item || 'false' );
} catch( e ) {
return false;
}
},
clear: function( expired ) {
var item, key;
var now = +new Date();
try {
for ( item in localStorage ) {
key = item.split( storagePrefix )[ 1 ];
if ( key && ( !expired || this.get( key ).expire <= now ) ) {
this.remove( key );
}
}
return this;
} catch( e ) {
return false;
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment