just-storage
v1.0.2
Published
Just localStorage with memory fallback. Works in edge cases like Safari private browsing.
Downloads
392
Maintainers
Readme
just-storage
Just localStorage with a memory fallback.
A barebones localStorage module that checks for not only the existance of localStorage, but also checks that localStorage is enabled in the current session. Falls back to memory storage if localStorage isn't supported.
This implementation works in cases like Safari private browsing, where every call to localStorage throws a quota exceeded error.
Also does simple JSON stringify/parse for you.
Install
$ npm install --save just-storage
Usage
var storage = require('just-storage')
storage.set('key', { some: 'value' }) // ==> saves and returns { some: 'value' }
storage('key') // ==> { some: 'value' }
var tokenStorage = storage.forKey('myJwt')
tokenStorage() // ==> returns current value of 'myJwt'
tokenStorage.set('19dk2924ksdf') // ==> saves new value to 'myJwt'
API
justStorage(key)
-> value
key
Required
Type: string
The key to load from storage.
Returns value
The value saved for key.
justStorage.set(key, value)
-> value
key
Required string
The key you're saving to.
value
Required any
The value you're saving for key
.
justStorage.forKey(key)
-> keyStorageFn
keyStorageFn()
-> value
Returns current saved value for key
keyStorageFn.set(value)
-> value
value
Required any
The value you're saving for key
.
License
MIT © Andrew Joslin