Skip to content

Instantly share code, notes, and snippets.

@HenriqueSilverio
Created November 17, 2013 20:36
Show Gist options
  • Save HenriqueSilverio/7517959 to your computer and use it in GitHub Desktop.
Save HenriqueSilverio/7517959 to your computer and use it in GitHub Desktop.
//------------------------------------------
// localStorage API and JSON objects
var TodoApp = TodoApp || {};
(function(App) {
App.storage = App.storage || {};
App.storage.set = function set(key, value) {
if(!key || !value) { return; }
if(typeof value === 'object') {
var data = JSON.stringify(value);
}
window.localStorage.setItem(key, data);
};
App.storage.get = function get(key) {
var data = window.localStorage.getItem(key);
if(!data) { return; }
if(data[0] === '{') {
data = JSON.parse(data);
}
return data;
};
}(TodoApp));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment