fallbackstorage
v0.0.2
Published
A fallback chain of localStorage/sesisonStorage/memoryStorage
Downloads
3
Readme
Fallback Storage
A fallback chain for localStorage/sessionStorage/memoryStorage.
Usage
import {getSafeStorage} from 'fallbackstorage'
getSafeStorage
check for availability and returns window.localStorage
, or window.sessionStorage
if they are available.
Otherwise, it returns the manually implemented MemoryStorage
instance.
The MemoryStorage
implementation follows the specification defined at whatwg.
Why this package
In safari's private mode, or when the user has disabled local storage, the window.localStorage
object is available (i.e., not null) but does not allow using storage.setItem
.
Therefore, the availability check is not straightforward as it seems to be.