td-storage
v1.1.4
Published
local storage methods
Downloads
3
Maintainers
Readme
td-storage
Helper functions to access local storage, wrapped in try catches and JSON parsing taken care of.
Install
yarn add td-storage
Configuration
Support for both localStorage
and sessionStorage
.
import storageFactory from 'td-storage';
const store = storageFactory({
driver: 'localStorage', // 'sessionStorage'
name: 'my-cool-app',
});
/**
* each instance of the storageFactory is prefixed with the provided name
* i.e the below will be stored under "my-cool-app/my-key"
*/
store.set(key, 'any value'); // => void
Methods (has, get, set, remove)
const key = 'my-key';
store.has(key); // => false
store.get(key); // => null
store.set(key, 'any value'); // => void
store.has(key); // => true
store.get(key); // => 'any value'
store.remove(key); // => void
store.get(key); // => null