Skip to content

Instantly share code, notes, and snippets.

@theuves
Last active February 11, 2018 20:12
Show Gist options
  • Save theuves/a8a51af3948f7b464a23cffab8de66dc to your computer and use it in GitHub Desktop.
Save theuves/a8a51af3948f7b464a23cffab8de66dc to your computer and use it in GitHub Desktop.
A better `localStorage`.
"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;
{
"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