Skip to content

Instantly share code, notes, and snippets.

@fisknils
Last active February 4, 2018 10:57
Show Gist options
  • Save fisknils/52280dbaf9ef1b1035f1c3886ab2be59 to your computer and use it in GitHub Desktop.
Save fisknils/52280dbaf9ef1b1035f1c3886ab2be59 to your computer and use it in GitHub Desktop.
(()=>{
const localStorage_extension = (function(){
this._get = (label=>{
return JSON.parse(localStorage.getItem(label));
});
this._put = ((label,items)=>{
return localStorage.setItem(label,JSON.stringify(items));
});
this._push = ((label, item)=>{
var arr;
if(typeof this._get(label) !== 'object') {
arr = [];
} else {
arr = this._get(label);
}
if(arr.indexOf(item) < 0) arr.push(item);
return this._put(label,arr);
});
this._pop = ((label)=>{
var items, r;
items = this._get(label);
r = items.pop();
this._put(label,items);
return r;
});
this._find = ((label,item)=>{
var lb = this._get(label);
var i = lb.indexOf(item);
return (i < 0 ? false : lb[i]);
});
});
window.lstore = new localStorage_extension();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment