Last active
February 11, 2018 20:12
-
-
Save theuves/a8a51af3948f7b464a23cffab8de66dc to your computer and use it in GitHub Desktop.
A better `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
"use strict"; | |
class LocalStorage { | |
constructor(prefix) { | |
this.prefix = prefix + "-"; | |
} | |
getItem(name) { | |
return JSON.parse(localStorage.getItem(this.prefix + name)); | |
} | |
hasItem(name) { | |
return localStorage.hasOwnProperty(this.prefix + name); | |
} | |
removeItem(name) { | |
return localStorage.removeItem(this.prefix + name); | |
} | |
setItem(name, value) { | |
return localStorage.setItem(this.prefix + name, JSON.stringify(value)); | |
} | |
} | |
export default 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
{ | |
"name": "local-storage", | |
"main": "./index.js", | |
"version": "0.0.1", | |
"author": "Matheus Alves", | |
"license": "MIT" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment