1.0.9 • Published 8 years ago

json-web-storage v1.0.9

Weekly downloads
66
License
MIT
Repository
github
Last release
8 years ago

JSON Web Storage Build Status

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