JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 74094
  • Score
    100M100P100Q171019F
  • License MIT

Tiny LocalStorage utility library

Package Exports

  • @analytics/localstorage-utils
  • @analytics/localstorage-utils/dist/analytics-util-localstorage.js
  • @analytics/localstorage-utils/dist/analytics-util-localstorage.module.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@analytics/localstorage-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

LocalStorage Utilities

A tiny localStorage utility library with fallbacks in 231 bytes.

This module will automatically fail back to global window storage if localStorage is not available.

Exposes hasLocalStorage, getItem, setItem, & removeItem functions.

See live demo.

How to install

Install @analytics/localstorage-utils from npm.

npm install @analytics/localstorage-utils

API

Below is the api for @analytics/localstorage-utils. These utilities are tree-shakable.

hasLocalStorage

Check if localStorage is supported

import { hasLocalStorage } from '@analytics/localstorage-utils'

if (hasLocalStorage()) {
  // Use local storage 
}

getItem

Get a localStorage value.

import { getItem } from '@analytics/localstorage-utils'

const value = getItem('cookie-key')

setItem

Set a localStorage value.

import { setItem } from '@analytics/localstorage-utils'

setItem('item-key', 'a')

removeItem

Delete a localStorage value.

import { removeItem } from '@analytics/localstorage-utils'

removeItem('key')