A tiny sessionStorage utility library with fallbacks in 239 bytes
.
This module will automatically fail back to global window storage if sessionStorage
is not available.
Exposes hasSessionStorage
, getItem
, setItem
, & removeItem
functions.
Install @analytics/session-storage-utils
from npm.
npm install @analytics/session-storage-utils
Below is the api for @analytics/session-storage-utils
. These utilities are tree-shakable.
Check if sessionStorage is supported
import { hasSessionStorage } from '@analytics/session-storage-utils'
if (hasSessionStorage()) {
// Use session storage
}
Get a sessionStorage value.
import { getSessionItem } from '@analytics/session-storage-utils'
const value = getItem('item-key')
Set a sessionStorage value.
import { setSessionItem } from '@analytics/session-storage-utils'
setSessionItem('item-key', 'a')
Delete a sessionStorage value.
import { removeSessionItem } from '@analytics/session-storage-utils'
removeSessionItem('item-key')