@analytics/localstorage-utils

    0.1.8 • Public • Published

    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')

    Install

    npm i @analytics/localstorage-utils

    DownloadsWeekly Downloads

    64,981

    Version

    0.1.8

    License

    MIT

    Unpacked Size

    52.5 kB

    Total Files

    25

    Last publish

    Collaborators

    • davidwells