@analytics/localstorage-utils — Tiny LocalStorage utility library. One of the small, focused utility packages that power the analytics library, usable standalone.
Full documentation, synced from the package README:
A tiny localStorage utility library with fallbacks in 227 bytes.
This module will automatically fail back to global window storage if localStorage is not available.
Exposes hasLocalStorage, getItem, setItem, & removeItem functions.
Install @analytics/localstorage-utils from npm.
npm install @analytics/localstorage-utilsBelow is the api for @analytics/localstorage-utils. These utilities are tree-shakable.
hasLocalStorageCheck if localStorage is supported
import { hasLocalStorage } from '@analytics/localstorage-utils'
if (hasLocalStorage()) {
// Use local storage
}getItemGet a localStorage value.
import { getItem } from '@analytics/localstorage-utils'
const value = getItem('cookie-key')setItemSet a localStorage value.
import { setItem } from '@analytics/localstorage-utils'
setItem('item-key', 'a')removeItemDelete a localStorage value.
import { removeItem } from '@analytics/localstorage-utils'
removeItem('key')