Skip to content

Instantly share code, notes, and snippets.

@tkazec
Last active December 19, 2015 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tkazec/5950846 to your computer and use it in GitHub Desktop.
Save tkazec/5950846 to your computer and use it in GitHub Desktop.
localStorage abstraction (ish)
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