Small wrapper for the Web Storage API which provides safe access to localStorage and sessionStorage.
- Ensures sessionStorage and localStorage is available and working before using it
- Replace Web Storage API methods with a simple API of getters and setters
- Automatically stringify and parse JSON
- Automatically convert boolean strings to proper booleans
WebStorage.js consists of two separate namespaces. One is WebStorage.Local
and
the other is WebStorage.Session
. The types of storage are very different and
you can read about them at MDN.
- Support check:
WebStorage.Local.enabled()
- Set:
WebStorage.Local.set(name, value)
- Get:
WebStorage.Local.get(name)
- Remove:
WebStorage.Local.remove(name)
- Support check:
WebStorage.Session.enabled()
- Set:
WebStorage.Session.set(name, value)
- Get:
WebStorage.Session.get(name)
- Remove:
WebStorage.Session.remove(name)
We started seeing errors that resulted from localStorage or sessionStorage not being available. The browser would be modern but the user may be browsing privately in Safari or may have disabled Web Storage on their own. In one case, our users would see our welcome tour on each login because localStorage was disabled across all company browsers.
The MIT License