Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@analytics/storage-utils

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@analytics/storage-utils

Storage utilities for saving values in browser

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
141K
decreased by-7.06%
Maintainers
1
Weekly downloads
 
Created
Source

Analytics Storage Utils

Storage utilities for analytics

Storage tries to use localStorage then cookies then defaults to global window.

It's also possible to specify exactly where to set, get, and remove data from with the options parameter.

getItem

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

// Default lookup, will try resolve value from `localStorage` -> `cookies` -> `global`
const value = getItem('key')

// Get value from specifically localStorage
const getLSValue = getItem('key', 'localStorage')

// Get value from specifically a cookie
const getLSValue = getItem('key', 'cookie')

// Get value from specifically the global window (or global this in Node)
const getLSValue = getItem('key', 'global')

// Get value from all locations
const valueObj = getItem('otherKey', 'all')
// {cookie: undefined, localStorage: "hahaha", global: null}

setItem

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

// Will try save value to `localStorage` -> `cookies` -> `global`
setItem('key', 'value')
// -> { value: "value", oldValue: "old", location: "localStorage" }

// Set value to specifically localStorage
setItem('key', 'otherValue', 'localStorage')
// -> { value: "otherValue", oldValue: "value", location: "localStorage" }

// Set value from specifically a cookie
setItem('keyTwo', 'cookieVal', 'cookie')
// -> { value: "cookieVal", oldValue: "null", location: "cookie" }

// Set value from specifically the global window (or global this in Node)
setItem('keyThree', 'xyz', 'global')
// -> { value: "xyz", oldValue: "foobar", location: "global" }

removeItem

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

// Will try save value to `localStorage` -> `cookies` -> `global`
setItem('key')
// -> { location: "localStorage" }

// Set value to specifically localStorage
setItem('key', 'otherValue', 'localStorage')
// -> { location: "localStorage" }

// Set value from specifically a cookie
setItem('keyTwo', 'cookieVal', 'cookie')
// -> { value: "cookieVal", oldValue: "null", location: "cookie" }

// Set value from specifically the global window (or global this in Node)
setItem('keyThree', 'xyz', 'global')
// -> { value: "xyz", oldValue: "foobar", location: "global" }

Keywords

FAQs

Package last updated on 03 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc