dw-localstore

0.0.6 • Public • Published

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.

License [MIT]

Package Sidebar

Install

npm i dw-localstore

Weekly Downloads

0

Version

0.0.6

License

MIT

Unpacked Size

3.38 kB

Total Files

3

Last publish

Collaborators

  • dawsmith06