Watch changes in browser localStorage
Simply run npm install localstorage-watcher --save
or clone the repository.
The whole system works on storageWatcher
global variable.
settings
private property, an object that holds default settings. Default settings are:- duration defaults to 1500ms or 1.5 seconds
- logType defaults to "info" which logger will use to run
console.info
. Other options areerror
,log
,table
,warn
- verbose defaults to
true
that will allow logger to log changes, difference of storageWatcher.lastStorage and window.localStorage. To turn logger off, change this tofalse
configure
public method, this method configures settings.start
public method, starts the watcherstop
public method, stops the watcherlastStorage
public property, holds last storage object before recent change
var watcher = storageWatcher;
// Configure watcher
watcher.configure({
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.lastStorage
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.