How to use the @analytics/cookie-utils.hasCookieSupport function in @analytics/cookie-utils

To help you get started, we’ve selected a few @analytics/cookie-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DavidWells / analytics / packages / analytics-util-storage / src / index.js View on Github external
import { getCookie, setCookie, removeCookie, hasCookieSupport } from '@analytics/cookie-utils'
import hasLocalStorageSupport from './hasLocalStorage'
import parse from './utils/parse'
import globalContext from './utils/globalContext'

// Constants
const LOCAL_STORAGE = 'localStorage'
const COOKIE = 'cookie'
const GLOBAL = 'global'

// Verify support
const hasStorage = hasLocalStorageSupport()
const hasCookies = hasCookieSupport()

/**
 * Get storage item from localStorage, cookie, or window
 * @param  {string} key - key of item to get
 * @param  {object|string} [options] - storage options. If string location of where to get storage
 * @param  {string} [options.storage] - Define type of storage to pull from.
 * @return {Any}  the value of key
 */
export function getItem(key, options = {}) {
  if (!key) return null
  const storageType = getStorageType(options)
  // Get value from all locations
  if (storageType === 'all') return getAll(key)
  /* 1. Try localStorage */
  if (useLocal(storageType)) {
    const value = localStorage.getItem(key)