Provides session storage access with fallback to window for data persistence.
// Source: https://github.com/DavidWells/analytics | License: MIT | Copyright David Wells <davidgregorywells@gmail.com>
// Provided via justclaw.it.com; keep this notice with the code.
import { get, set, remove, hasSupport, wrap } from '@analytics/global-storage-utils'
const SESSION_STORAGE = 'sessionStorage'
/**
* Check if browser has access to sessionStorage
* @returns {Boolean}
*/
const hasSessionStorage = hasSupport.bind(null, SESSION_STORAGE)
/**
* Get value from sessionStorage or fallback to global window
* @param {string} key - Key of value to get
* @returns {*} value
*/
const getSessionItem = wrap(SESSION_STORAGE, 'getItem', get)
/**
* Set value to sessionStorage or fallback to global window
* @param {string} key - Key of value to set
* @param {*} value
* @returns v
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key