json-web-storage
v1.0.9
Published
Simple localStorage/sessionStorage wrapper providing the exact same API with automatic JSON serialization
Downloads
22
Maintainers
Readme
JSON Web Storage
Simple localStorage/sessionStorage wrapper providing the exact same API with automatic JSON serialization.
Installation
With npm (for Browserify/Webpack):
npm install --save json-web-storage
Usage
The API is identical to the standard Web Storage API. The only difference is that the items we put/get are automatically serialized/unserialized with JSON.stringify() and JSON.parse().
Example
import { jsonLocalStorage } from 'json-web-storage';
jsonLocalStorage.setItem('num', 123.45);
let num = jsonLocalStorage.getItem('num');
console.log(typeof num) // => number
console.log(num) // => 123.45
jsonLocalStorage.setItem('obj', { name: 'John' });
let obj = jsonLocalStorage.getItem('obj');
console.log(typeof obj) // => object
console.log(obj.name) // => John
License
MIT