dw-localstore
v0.0.6
Published
My way to use localstorage
Downloads
3
Maintainers
Readme
LocalStore
A small and simple free dependency to manage localstorage.
Installation
npm install dw-localstore
Usage
Forget about JSON.parse and JSON.stringify
const localStore = require('dw-localstore')
localStore.set("color",{
id : 1
name : "red"
});
let color = localStore.get("color");
console.log(color); // color object
Add a new property or update an existing one
localStore.update("color",{
id : 2
description:"My favorite color"
});
Listen for changes
localStore.subscribe("color",(data)=>{
console.log("color key has changed",data);
})
Use has and hasProperty methods for validations
if(localStore.has("color") && localStore.hasProperty("color","id")){
console.log("valid color");
}
Remove a key
localStore.remove("color")
For defaults data declare the global variable (schemas)
window.schemas = {
"dog" : {id:1,name:"Poppy"}
};
let dog = localStore.get("dog");
console.log(dog);
Note
All data is saved base64 encoded
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.