Skip to content

Instantly share code, notes, and snippets.

@albinotonnina
Forked from tkazec/data.js
Last active August 29, 2015 14:08
Show Gist options
  • Save albinotonnina/3561e385754ba41fc66e to your computer and use it in GitHub Desktop.
Save albinotonnina/3561e385754ba41fc66e to your computer and use it in GitHub Desktop.
var Data = {
has: function (key) {
return localStorage.getItem(key) !== null;
},
get: function (key) {
return Data.has(key) ? JSON.parse(localStorage.getItem(key)) : undefined;
},
set: function (key, val) {
localStorage.setItem(key, JSON.stringify(val));
},
def: function (key, val) {
!Data.has(key) && Data.set(key, val);
},
del: function (key) {
localStorage.removeItem(key);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment