A wrapper around localstorage, sessionstorage and cookies for client side config storage
$ npm i browser-configstore
$ yarn add browser-configstore
import { getConfig, setConfig, deleteConfig, SESSION } from 'browser-configstore'
setConfig('foo', true)
console.log(getConfig('foo')) // true
deleteConfig('foo')
console.log(getConfig('foo')) // undefined
// save an object
const obj = { count: 1, hello: 'world' }
setConfig('myObject', obj)
console.log(getConfig('myObject')) // { count: 1, hello: 'world' }
// save in session storage
setConfig('count', 23, SESSION)
console.log(getConfig('count', SESSION)) // 23
deleteConfig('count', SESSION)
console.log(getConfig('count', SESSION)) // undefined
Mode | Description |
---|---|
LOCAL | (default) use local storage |
SESSION | use session storage |
SESSION_OR_LOCAL | get the value from session first, failing that get the value from local storage |
NON_PERSISTENT | Store in a memory map, won't persist if page reloads/navigates away to another page (non-single page app) |
Get value stored in key
Store the given value (must be stringify
able) at the set key.
Remove the given key from storage.
Gets the given key from the stored cookie.
Set the given value at the key in the cookie, with an optional expiry time in days on the cookie.
Remove the given key from the cookie.