Skip to content

Latest commit

 

History

History
87 lines (58 loc) · 1.53 KB

README.md

File metadata and controls

87 lines (58 loc) · 1.53 KB

tiny-storage

A tiny localStorage util

Build Status

Documentation

Use localStorage within namespaces

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'

get set

store.set('apple', 3);
store.set('lemon', 4);

store.get('apple'); // 3
store.get('lemon'); // 4

remove

store.set('apple', 3);
store.get('apple'); // 4

store.remove('apple'); // 4
store.get('apple'); // null

clear

store.set('apple', 3);
store.set('lemon', 4);

store.clear();
store.get('apple'); // null
store.get('lemon'); // null

all

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' ]
// }