text: 'use strict';
  
  Object.defineProperty(exports, '__esModule', { value: true });
  
  var cookieUtils = require('@analytics/cookie-utils');
  
  function hasLocalStorage() {
  
    try {
      if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
        return false;
      } // test for safari private
  
  
      localStorage.setItem('__test', '1');
      localStorage.removeItem('__test');
    } catch (err) {
      return false;
    }
  
    return true;
  }
  
  function _typeof(obj) {
    if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
      _typeof = function (obj) {
        return typeof obj;
      };
    } else {
      _typeof = function (obj) {
        return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
      };
    }
  
    return _typeof(obj);
  }
  
  function parse(input) {
    var value;
  
    try {
      value = JSON.parse(input);
  
      if (typeof value === 'undefined') {
        value = input;
      }
  
      if (value === 'true') {
        value = true;
      }
  
      if (value === 'false') {
        value = false;
      }
  
      if (parseFloat(value) === value && _typeof(value) !== 'object') {
        value = parseFloat(value);
      }
    } catch (e) {
      value = input;
    }
  
    return value;
  }
  
  /* global self globalThis */
  function getGlobalThis() {
    if (typeof globalThis !== 'undefined') return globalThis;
    if (typeof global !== 'undefined') return global;
    if (typeof self !== 'undefined') return self;
    /* eslint-disable-line no-restricted-globals */
  
    if (typeof window !== 'undefined') return window;
    if (typeof this !== 'undefined') return this;
    return {}; // should never happen
  }
  /* tinier from https://github.com/purposeindustries/window-or-global/blob/master/lib/index.js
  const context = (typeof self === 'object' && self.self === self && self) || // eslint-disable-line
    (typeof global === 'object' && global.global === global && global) ||
    this
  export default context
  */
  
  var LOCAL_STORAGE = 'localStorage';
  var COOKIE = 'cookie';
  var GLOBAL = 'global'; // Verify support
  
  var hasStorage = hasLocalStorage();
  var hasCookies = cookieUtils.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
   */
  
  function getItem(key) {
    var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
    if (!key) return null;
    var storageType = getStorageType(options); // Get value from all locations
  
    if (storageType === 'all') return getAll(key);
    /* 1. Try localStorage */
  
    if (useLocal(storageType)) {
      var value = localStorage.getItem(key);
      if (value || storageType === LOCAL_STORAGE) return parse(value);
    }
    /* 2. Fallback to cookie */
  
  
    if (useCookie(storageType)) {
      var _value = cookieUtils.getCookie(key);
  
      if (_value || storageType === COOKIE) return parse(_value);
    }
    /* 3. Fallback to window/global. */
  
  
    return getGlobalThis[key] || null;
  }
  
  function getAll(key) {
    return {
      cookie: parse(cookieUtils.getCookie(key)),
      localStorage: parse(localStorage.getItem(key)),
      global: getGlobalThis[key] || null
    };
  }
  /**
   * Store values in localStorage, cookie, or window
   * @param {string} key - key of item to set
   * @param {*} value - value of item to set
   * @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.
   * @returns {object} returns old value, new values, & location of storage
   */
  
  
  function setItem(key, value) {
    var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
    if (!key || !value) return false;
    var storageType = getStorageType(options);
    var saveValue = JSON.stringify(value);
    /* 1. Try localStorage */
  
    if (useLocal(storageType)) {
      // console.log('SET as localstorage', saveValue)
      var _oldValue = parse(localStorage.getItem(key));
  
      localStorage.setItem(key, saveValue);
      return {
        value: value,
        oldValue: _oldValue,
        location: LOCAL_STORAGE
      };
    }
    /* 2. Fallback to cookie */
  
  
    if (useCookie(storageType)) {
      // console.log('SET as cookie', saveValue)
      var _oldValue2 = parse(cookieUtils.getCookie(key));
  
      cookieUtils.setCookie(key, saveValue);
      return {
        value: value,
        oldValue: _oldValue2,
        location: COOKIE
      };
    }
    /* 3. Fallback to window/global */
  
  
    var oldValue = getGlobalThis[key];
    getGlobalThis[key] = value;
    return {
      value: value,
      oldValue: oldValue,
      location: GLOBAL
    };
  }
  /**
   * Remove values from localStorage, cookie, or window
   * @param {string} key - key of item to set
   * @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.
   */
  
  function removeItem(key) {
    var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
    if (!key) return false;
    var storageType = getStorageType(options);
  
    if (useLocal(storageType)) {
      /* 1. Try localStorage */
      localStorage.removeItem(key);
      return LOCAL_STORAGE;
    } else if (useCookie(storageType)) {
      /* 2. Fallback to cookie */
      cookieUtils.removeCookie(key);
      return COOKIE;
    }
    /* 3. Fallback to window/global */
  
  
    getGlobalThis[key] = null;
    return GLOBAL;
  }
  
  function getStorageType(options) {
    return typeof options === 'string' ? options : options.storage;
  }
  
  function useLocal(storage) {
    return hasStorage && (!storage || storage === LOCAL_STORAGE);
  }
  
  function useCookie(storage) {
    return hasCookies && (!storage || storage === COOKIE);
  }
  var index = {
    getItem: getItem,
    setItem: setItem,
    removeItem: removeItem
  };
  
  exports.getCookie = cookieUtils.getCookie;
  exports.setCookie = cookieUtils.setCookie;
  exports.removeCookie = cookieUtils.removeCookie;
  exports.hasCookieSupport = cookieUtils.hasCookieSupport;
  exports.getItem = getItem;
  exports.setItem = setItem;
  exports.removeItem = removeItem;
  exports.hasLocalStorageSupport = hasLocalStorage;
  exports.default = index;
  