Created
January 2, 2015 15:08
-
-
Save justmarkup/c1c9da55d4c84fcca084 to your computer and use it in GitHub Desktop.
basket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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