1.0.2 • Published 9 years ago
localstorage-watcher v1.0.2
LocalStorage watcher
Watch changes in browser localStorage
Installation
Simply run npm install localstorage-watcher --save or clone the repository.
Usage
The whole system works on storageWatcher global variable.
Methods and Properties
settingsprivate property, an object that holds default settings. Default settings are: 1. duration defaults to 1500ms or 1.5 seconds 2. logType defaults to "info" which logger will use to runconsole.info. Other options areerror,log,table,warn3. verbose defaults totruethat will allow logger to log changes, difference of storageWatcher.lastStorage and window.localStorage. To turn logger off, change this tofalseconfigurepublic method, this method configures settings.startpublic method, starts the watcherstoppublic method, stops the watcherlastStoragepublic property, holds last storage object before recent change
Using methods
var watcher = storageWatcher;
// Configure watcher
watcher.configue({
verbose: true, // (Bool) Default: true
duration: 3000, // (Integer) Default: 1500
logType: 'warn' // (String) Default: 'info'
})
// Start watcher
watcher.start();
// add to storage to see the watcher's behavior
localStorage.setItem('testKey', 'testValue');
// on next watch cycle, the watcher will log the change and the difference of watcher.lastStorage and window.localStorage
// Stop watcher
watcher.stop()
// Get the last saved storage
watcher.lastStorageExample
In the example folder, open index.html in browser and you will see a logger system similar to your browser console and bunch of useful buttons.