Created
March 22, 2017 21:29
-
-
Save brito/bf77ccff19b8f24932433d635fd88241 to your computer and use it in GitHub Desktop.
Use and test localStorage
This file contains hidden or 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
N = 'Use and test localStorage' | |
if ('test') | |
console.clear(), | |
localStorage.length ? | |
GET(N).ok || | |
console.warn(N, 'not empty'): | |
SET(N, { ok: true }); | |
_LIST(); | |
if ('mop') | |
console.assert(GET(N).ok), | |
localStorage.removeItem(N), | |
console.assert(!GET(N)), | |
console.info('Tests ok'); | |
function SET(key, value){ | |
return localStorage.setItem(key, JSON.stringify(value) ), GET(key) } | |
function GET(key, reviver){ | |
return JSON.parse(localStorage.getItem(key), reviver) } | |
function _LIST(){ | |
Object.keys(localStorage) | |
.forEach(key => console.log(key, GET(key))) } | |
// | |
new Date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment