A tiny localStorage util
import Storage from 'storage.js';
const store = new Storage('store');
const cart = new Storage('cart');
store.set('book-001', 'Robinson Crusoe');
store.set('book-002', "Grimm's Fairy Tales");
store.set('book-003', 'Martin Eden');
cart.set('book-001', 'The Golden Bough');
cart.set('book-002', 'Moon and Sixpence');
cart.set('book-003', 'Leaves of Grass');
store.get('book-001'); // 'Robinson Crusoe'
store.get('book-002'); // "Grimm's Fairy Tales"
store.get('book-003'); // 'Martin Eden'
cart.get('book-001'); // 'The Golden Bough'
cart.get('book-002'); // 'Moon and Sixpence'
cart.get('book-003'); // 'Leaves of Grass'
store.set('apple', 3);
store.set('lemon', 4);
store.get('apple'); // 3
store.get('lemon'); // 4
store.set('apple', 3);
store.get('apple'); // 4
store.remove('apple'); // 4
store.get('apple'); // null
store.set('apple', 3);
store.set('lemon', 4);
store.clear();
store.get('apple'); // null
store.get('lemon'); // null
import Storage from 'storage.js';
const myStore = new Storage('store');
myStore.set('apple', 3);
myStore.set('lemon', 4);
myStore.set('animals', [ 'fox', 'dog' ]);
myStore.all();
// {
// apple: 3,
// lemon: 4,
// animals: [ 'fox', 'dog' ]
// }