Last active
February 4, 2018 10:57
-
-
Save fisknils/52280dbaf9ef1b1035f1c3886ab2be59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(()=>{ | |
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