Universal code for storing data in local storage or cookie, if local storage is not available
npm install @divante/data-storageUniversal code for storing data in local storage or cookie, if local storage is not available.
javascript
let DataStorage = require('@divante/data-storage');DataStorage.setValue("foo", "bar"); // setter
DataStorage.getValue("foo"); //returns "bar"
DataStorage.getValue("baz"); //returns undefined
DataStorage.getValue("baz", "default value"); //returns "default value"
DataStorage.isValueSet("foo"); //true
DataStorage.isValueSet("baz"); //false
DataStorage.setObjectValue("baz", {a: 15, b: [3, 4]}); //Stores as JSON
DataStorage.getObjectValue("baz"); // {a: 15, b: [3, 4]}
DataStorage.getObjectValue("baz2"); // undefined
DataStorage.getObjectValue("baz2", {}); // {}
``