Skip to content

Instantly share code, notes, and snippets.

@maxkrieger
Last active December 24, 2015 20:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxkrieger/6860847 to your computer and use it in GitHub Desktop.
Save maxkrieger/6860847 to your computer and use it in GitHub Desktop.
A localStorage library of epic proportions ;)
/*
SJS, a localStorage library of epic proportions.
usage:
saving:
s.set("myKey", myObject);
retrieving:
s.get("myKey");
returns myObject
*/
var s = {
set: function(key, val){
localStorage[key] = JSON.stringify(val);
return s.get(key);
},
get: function(key){
if(localStorage[key] !== undefined) return JSON.parse(localStorage[key]);
else return undefined;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment