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 - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [0.2.6](https://github.com/DavidWells/analytics/compare/@analytics/storage-utils@0.2.5...@analytics/storage-utils@0.2.6) (2021-07-20)
**Note:** Version bump only for package @analytics/storage-utils
## [0.2.5](https://github.com/DavidWells/analytics/compare/@analytics/storage-utils@0.2.4...@analytics/storage-utils@0.2.5) (2021-03-11)

@@ -8,0 +16,0 @@

145

dist/@analytics/storage-utils.js

@@ -67,72 +67,59 @@ var analyticsUtilStorage = (function (exports) {

function cookie(name, value, ttl, path, domain, secure) {
if (typeof window === 'undefined') return;
/* Set values */
var l = "object" == typeof self && self.self === self && self || "object" == typeof global && global.global === global && global || void 0;
if (arguments.length > 1) {
// eslint-disable-next-line no-return-assign
return document.cookie = name + '=' + encodeURIComponent(value) + ( // eslint-disable-next-line operator-linebreak
!ttl ? '' : // Has TTL set expiration on cookie
'; expires=' + new Date(+new Date() + ttl * 1000).toUTCString() + ( // If path set path
!path ? '' : '; path=' + path) + ( // If domain set domain
!domain ? '' : '; domain=' + domain) + ( // If secure set secure
!secure ? '' : '; secure'));
}
function o(o) {
return l[o];
}
return decodeURIComponent((('; ' + document.cookie).split('; ' + name + '=')[1] || '').split(';')[0]);
function e(o, e) {
return l[o] = e, e;
}
function hasCookieSupport() {
try {
var key = '_c_'; // Try to set cookie
function f(l) {
e(l, void 0);
}
cookie(key, '1');
var valueSet = document.cookie.indexOf(key) !== -1; // Cleanup cookie
var r = "undefined",
a = l$1();
cookie(key, '', -1);
return valueSet;
} catch (e) {
return false;
function l$1(t) {
if (void 0 === t && (t = !1), typeof a !== r && !t) return a;
a = !0;
try {
typeof localStorage !== r && typeof JSON !== r || (a = !1), localStorage.setItem("_" + r, "1"), localStorage.removeItem("_" + r);
} catch (t) {
a = !1;
}
return a;
}
/**
* Get a cookie value
* @param {string} name - key of cookie
* @return {string} value of cookie
*/
var n$1 = "undefined",
i = a$1(),
r$1 = d,
c$1 = d;
var getCookie = cookie;
/**
* Set a cookie value
* @param {string} name - key of cookie
* @param {string} value - value of cookie
* @param {string} days - days to keep cookie
*/
var setCookie = cookie;
/**
* Remove a cookie value.
* @param {string} name - key of cookie
*/
function removeCookie(name) {
return cookie(name, '', -1);
function u$1(e$$1) {
return i ? d(e$$1, "", -1) : f(e$$1);
}
function hasLocalStorage() {
function a$1(e$$1) {
if (void 0 === e$$1 && (e$$1 = !1), typeof i !== n$1 && !e$$1) return i;
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
var o$$1 = "_" + n$1;
d(o$$1, "1"), i = -1 !== document.cookie.indexOf(o$$1), d(o$$1, "", -1);
} catch (e$$1) {
i = !1;
}
return i;
}
localStorage.setItem('_t_', '1');
localStorage.removeItem('_t_');
} catch (err) {
return false;
function d(t, r, c, u, a, d) {
if (typeof window !== n$1) {
var f$$1 = arguments.length > 1;
return i || (f$$1 ? e(t, r) : o(t)), f$$1 ? document.cookie = t + "=" + encodeURIComponent(r) + (c ? "; expires=" + new Date(+new Date() + 1e3 * c).toUTCString() + (u ? "; path=" + u : "") + (a ? "; domain=" + a : "") + (d ? "; secure" : "") : "") : decodeURIComponent((("; " + document.cookie).split("; " + t + "=")[1] || "").split(";")[0]);
}
return true;
}

@@ -168,4 +155,2 @@

var globalContext = (typeof self === "undefined" ? "undefined" : _typeof(self)) === 'object' && self.self === self && self || (typeof global === "undefined" ? "undefined" : _typeof(global)) === 'object' && global.global === global && global || undefined;
var ALL = '*';

@@ -176,4 +161,4 @@ var LOCAL_STORAGE = 'localStorage';

var hasStorage = hasLocalStorage();
var hasCookies = hasCookieSupport();
var hasStorage = l$1();
var hasCookiesSupport = a$1();
/**

@@ -189,3 +174,3 @@ * Get storage item from localStorage, cookie, or window

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return null;
if (!key) return;
var storageType = getStorageType(options); // Get value from all locations

@@ -204,3 +189,3 @@

if (useCookie(storageType)) {
var _value = getCookie(key);
var _value = r$1(key);

@@ -212,3 +197,3 @@ if (_value || storageType === COOKIE) return parse(_value);

return globalContext[key] || null;
return o(key);
}

@@ -218,5 +203,5 @@

return {
cookie: parse(getCookie(key)),
cookie: parse(r$1(key)),
localStorage: parse(localStorage.getItem(key)),
global: globalContext[key] || null
global: o(key)
};

@@ -272,6 +257,6 @@ }

current: value,
previous: parse(getCookie(key)) // Set Cookie
previous: parse(r$1(key)) // Set Cookie
};
setCookie(key, saveValue);
c$1(key, saveValue);

@@ -292,6 +277,6 @@ if (!setAll) {

current: value,
previous: globalContext[key] // Set global value
previous: o(key) // Set global value
};
globalContext[key] = value;
e(key, value);

@@ -317,3 +302,3 @@ if (!setAll) {

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return false;
if (!key) return;
var storageType = getStorageType(options);

@@ -331,3 +316,3 @@ var removeAll = storageType === ALL;

/* 2. Fallback to cookie */
removeCookie(key);
u$1(key);
locations.push(COOKIE);

@@ -339,3 +324,3 @@ }

if (removeAll || useGlobal(storageType)) {
globalContext[key] = undefined;
f(key);
locations.push(GLOBAL);

@@ -352,3 +337,3 @@ }

function useGlobal(storage) {
return !storage || storage === GLOBAL;
return useType(storage, GLOBAL);
}

@@ -358,3 +343,3 @@

// If has localStorage and storage option not defined, or is set to 'localStorage' or '*'
return hasStorage && (!storage || storage === LOCAL_STORAGE || storage === ALL);
return hasStorage && useType(storage, LOCAL_STORAGE);
}

@@ -364,4 +349,8 @@

// If has cookies and storage option not defined, or is set to 'cookies' or '*'
return hasCookies && (!storage || storage === COOKIE || storage === ALL);
return hasCookiesSupport && useType(storage, COOKIE);
}
function useType(storage, type) {
return !storage || storage === type || storage === ALL;
}
var index = {

@@ -380,8 +369,8 @@ getItem: getItem,

exports.removeItem = removeItem;
exports.getCookie = getCookie;
exports.setCookie = setCookie;
exports.removeCookie = removeCookie;
exports.globalContext = globalContext;
exports.hasLocalStorageSupport = hasLocalStorage;
exports.hasCookieSupport = hasCookieSupport;
exports.getCookie = r$1;
exports.setCookie = c$1;
exports.removeCookie = u$1;
exports.globalContext = l;
exports.hasLocalStorage = l$1;
exports.hasCookies = a$1;
exports.default = index;

@@ -388,0 +377,0 @@

@@ -1,1 +0,1 @@

var analyticsUtilStorage=function(e){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,o)}return r}function n(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(n,!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(n).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function i(e,t,r,o,n,i){if("undefined"!=typeof window)return arguments.length>1?document.cookie=e+"="+encodeURIComponent(t)+(r?"; expires="+new Date(+new Date+1e3*r).toUTCString()+(o?"; path="+o:"")+(n?"; domain="+n:"")+(i?"; secure":""):""):decodeURIComponent((("; "+document.cookie).split("; "+e+"=")[1]||"").split(";")[0])}function u(){try{i("_c_","1");var e=-1!==document.cookie.indexOf("_c_");return i("_c_","",-1),e}catch(e){return!1}}var c=i,l=i;function a(e){return i(e,"",-1)}function f(){try{if("undefined"==typeof localStorage||"undefined"==typeof JSON)return!1;localStorage.setItem("_t_","1"),localStorage.removeItem("_t_")}catch(e){return!1}return!0}function p(e){var r;try{void 0===(r=JSON.parse(e))&&(r=e),"true"===r&&(r=!0),"false"===r&&(r=!1),parseFloat(r)===r&&"object"!==t(r)&&(r=parseFloat(r))}catch(t){r=e}return r}var s="object"===("undefined"==typeof self?"undefined":t(self))&&self.self===self&&self||"object"===("undefined"==typeof global?"undefined":t(global))&&global.global===global&&global||void 0,g="*",v="localStorage",y="cookie",b="global",m=f(),d=u();function S(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e)return null;var r=I(t);if(r===g)return function(e){return{cookie:p(c(e)),localStorage:p(localStorage.getItem(e)),global:s[e]||null}}(e);if(j(r)){var o=localStorage.getItem(e);if(o||r===v)return p(o)}if(w(r)){var n=c(e);if(n||r===y)return p(n)}return s[e]||null}function O(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e&&void 0!==t){var o={},i=I(r),u=JSON.stringify(t),a=i===g;if(j(i)){var f={current:t,previous:p(localStorage.getItem(e))};if(localStorage.setItem(e,u),!a)return n({location:v},f);o[v]=f}if(w(i)){var m={current:t,previous:p(c(e))};if(l(e,u),!a)return n({location:y},m);o[y]=m}var d={current:t,previous:s[e]};return s[e]=t,a?(o[b]=d,o):n({location:b},d)}}function h(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e)return!1;var r,o=I(t),n=o===g,i=[];return(n||j(o))&&(localStorage.removeItem(e),i.push(v)),(n||w(o))&&(a(e),i.push(y)),!n&&((r=o)&&r!==b)||(s[e]=void 0,i.push(b)),i}function I(e){return"string"==typeof e?e:e.storage}function j(e){return m&&(!e||e===v||e===g)}function w(e){return d&&(!e||e===y||e===g)}var _={getItem:S,setItem:O,removeItem:h};return e.ALL=g,e.LOCAL_STORAGE=v,e.COOKIE=y,e.GLOBAL=b,e.getItem=S,e.setItem=O,e.removeItem=h,e.getCookie=c,e.setCookie=l,e.removeCookie=a,e.globalContext=s,e.hasLocalStorageSupport=f,e.hasCookieSupport=u,e.default=_,e}({});
var analyticsUtilStorage=function(e){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function r(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),o.push.apply(o,r)}return o}function n(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(n,!0).forEach(function(t){o(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(n).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var i="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||void 0;function a(e){return i[e]}function c(e,t){return i[e]=t,t}function u(e){c(e,void 0)}var f="undefined",l=s();function s(e){if(void 0===e&&(e=!1),typeof l!==f&&!e)return l;l=!0;try{typeof localStorage!==f&&typeof JSON!==f||(l=!1),localStorage.setItem("_"+f,"1"),localStorage.removeItem("_"+f)}catch(e){l=!1}return l}var p="undefined",g=b(),v=d,y=d;function m(e){return g?d(e,"",-1):u(e)}function b(e){if(void 0===e&&(e=!1),typeof g!==p&&!e)return g;try{var t="_"+p;d(t,"1"),g=-1!==document.cookie.indexOf(t),d(t,"",-1)}catch(e){g=!1}return g}function d(e,t,o,r,n,i){if(typeof window!==p){var u=arguments.length>1;return g||(u?c(e,t):a(e)),u?document.cookie=e+"="+encodeURIComponent(t)+(o?"; expires="+new Date(+new Date+1e3*o).toUTCString()+(r?"; path="+r:"")+(n?"; domain="+n:"")+(i?"; secure":""):""):decodeURIComponent((("; "+document.cookie).split("; "+e+"=")[1]||"").split(";")[0])}}function O(e){var o;try{void 0===(o=JSON.parse(e))&&(o=e),"true"===o&&(o=!0),"false"===o&&(o=!1),parseFloat(o)===o&&"object"!==t(o)&&(o=parseFloat(o))}catch(t){o=e}return o}var S="*",h="localStorage",I="cookie",j="global",w=s(),k=b();function C(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e){var o=D(t);if(o===S)return function(e){return{cookie:O(v(e)),localStorage:O(localStorage.getItem(e)),global:a(e)}}(e);if(A(o)){var r=localStorage.getItem(e);if(r||o===h)return O(r)}if(E(o)){var n=v(e);if(n||o===I)return O(n)}return a(e)}}function P(e,t){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e&&void 0!==t){var r={},i=D(o),u=JSON.stringify(t),f=i===S;if(A(i)){var l={current:t,previous:O(localStorage.getItem(e))};if(localStorage.setItem(e,u),!f)return n({location:h},l);r[h]=l}if(E(i)){var s={current:t,previous:O(v(e))};if(y(e,u),!f)return n({location:I},s);r[I]=s}var p={current:t,previous:a(e)};return c(e,t),f?(r[j]=p,r):n({location:j},p)}}function L(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e){var o=D(t),r=o===S,n=[];return(r||A(o))&&(localStorage.removeItem(e),n.push(h)),(r||E(o))&&(m(e),n.push(I)),(r||U(o,j))&&(u(e),n.push(j)),n}}function D(e){return"string"==typeof e?e:e.storage}function A(e){return w&&U(e,h)}function E(e){return k&&U(e,I)}function U(e,t){return!e||e===t||e===S}var _={getItem:C,setItem:P,removeItem:L};return e.ALL=S,e.LOCAL_STORAGE=h,e.COOKIE=I,e.GLOBAL=j,e.getItem=C,e.setItem=P,e.removeItem=L,e.getCookie=v,e.setCookie=y,e.removeCookie=m,e.globalContext=i,e.hasLocalStorage=s,e.hasCookies=b,e.default=_,e}({});

@@ -5,2 +5,4 @@ 'use strict';

var globalStorageUtils = require('@analytics/global-storage-utils');
var localstorageUtils = require('@analytics/localstorage-utils');
var cookieUtils = require('@analytics/cookie-utils');

@@ -71,19 +73,2 @@

function hasLocalStorage() {
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
localStorage.setItem('_t_', '1');
localStorage.removeItem('_t_');
} catch (err) {
return false;
}
return true;
}
function parse(input) {

@@ -117,4 +102,2 @@ var value;

var globalContext = (typeof self === "undefined" ? "undefined" : _typeof(self)) === 'object' && self.self === self && self || (typeof global === "undefined" ? "undefined" : _typeof(global)) === 'object' && global.global === global && global || undefined;
var ALL = '*';

@@ -125,4 +108,4 @@ var LOCAL_STORAGE = 'localStorage';

var hasStorage = hasLocalStorage();
var hasCookies = cookieUtils.hasCookieSupport();
var hasStorage = localstorageUtils.hasLocalStorage();
var hasCookiesSupport = cookieUtils.hasCookies();
/**

@@ -138,3 +121,3 @@ * Get storage item from localStorage, cookie, or window

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return null;
if (!key) return;
var storageType = getStorageType(options); // Get value from all locations

@@ -160,3 +143,3 @@

return globalContext[key] || null;
return globalStorageUtils.get(key);
}

@@ -168,3 +151,3 @@

localStorage: parse(localStorage.getItem(key)),
global: globalContext[key] || null
global: globalStorageUtils.get(key)
};

@@ -239,6 +222,6 @@ }

current: value,
previous: globalContext[key] // Set global value
previous: globalStorageUtils.get(key) // Set global value
};
globalContext[key] = value;
globalStorageUtils.set(key, value);

@@ -264,3 +247,3 @@ if (!setAll) {

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return false;
if (!key) return;
var storageType = getStorageType(options);

@@ -285,3 +268,3 @@ var removeAll = storageType === ALL;

if (removeAll || useGlobal(storageType)) {
globalContext[key] = undefined;
globalStorageUtils.remove(key);
locations.push(GLOBAL);

@@ -298,3 +281,3 @@ }

function useGlobal(storage) {
return !storage || storage === GLOBAL;
return useType(storage, GLOBAL);
}

@@ -304,3 +287,3 @@

// If has localStorage and storage option not defined, or is set to 'localStorage' or '*'
return hasStorage && (!storage || storage === LOCAL_STORAGE || storage === ALL);
return hasStorage && useType(storage, LOCAL_STORAGE);
}

@@ -310,4 +293,8 @@

// If has cookies and storage option not defined, or is set to 'cookies' or '*'
return hasCookies && (!storage || storage === COOKIE || storage === ALL);
return hasCookiesSupport && useType(storage, COOKIE);
}
function useType(storage, type) {
return !storage || storage === type || storage === ALL;
}
var index = {

@@ -319,6 +306,8 @@ getItem: getItem,

exports.globalContext = globalStorageUtils.globalContext;
exports.hasLocalStorage = localstorageUtils.hasLocalStorage;
exports.getCookie = cookieUtils.getCookie;
exports.setCookie = cookieUtils.setCookie;
exports.removeCookie = cookieUtils.removeCookie;
exports.hasCookieSupport = cookieUtils.hasCookieSupport;
exports.hasCookies = cookieUtils.hasCookies;
exports.ALL = ALL;

@@ -331,4 +320,2 @@ exports.LOCAL_STORAGE = LOCAL_STORAGE;

exports.removeItem = removeItem;
exports.globalContext = globalContext;
exports.hasLocalStorageSupport = hasLocalStorage;
exports.default = index;

@@ -1,3 +0,7 @@

import { hasCookieSupport, getCookie, setCookie, removeCookie } from '@analytics/cookie-utils';
export { getCookie, setCookie, removeCookie, hasCookieSupport } from '@analytics/cookie-utils';
import { get, set, remove } from '@analytics/global-storage-utils';
export { globalContext } from '@analytics/global-storage-utils';
import { hasLocalStorage } from '@analytics/localstorage-utils';
export { hasLocalStorage } from '@analytics/localstorage-utils';
import { hasCookies, getCookie, setCookie, removeCookie } from '@analytics/cookie-utils';
export { getCookie, setCookie, removeCookie, hasCookies } from '@analytics/cookie-utils';

@@ -67,19 +71,2 @@ function _typeof(obj) {

function hasLocalStorage() {
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
localStorage.setItem('_t_', '1');
localStorage.removeItem('_t_');
} catch (err) {
return false;
}
return true;
}
function parse(input) {

@@ -113,4 +100,2 @@ var value;

var globalContext = (typeof self === "undefined" ? "undefined" : _typeof(self)) === 'object' && self.self === self && self || (typeof global === "undefined" ? "undefined" : _typeof(global)) === 'object' && global.global === global && global || undefined;
var ALL = '*';

@@ -122,3 +107,3 @@ var LOCAL_STORAGE = 'localStorage';

var hasStorage = hasLocalStorage();
var hasCookies = hasCookieSupport();
var hasCookiesSupport = hasCookies();
/**

@@ -134,3 +119,3 @@ * Get storage item from localStorage, cookie, or window

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return null;
if (!key) return;
var storageType = getStorageType(options); // Get value from all locations

@@ -156,3 +141,3 @@

return globalContext[key] || null;
return get(key);
}

@@ -164,3 +149,3 @@

localStorage: parse(localStorage.getItem(key)),
global: globalContext[key] || null
global: get(key)
};

@@ -235,6 +220,6 @@ }

current: value,
previous: globalContext[key] // Set global value
previous: get(key) // Set global value
};
globalContext[key] = value;
set(key, value);

@@ -260,3 +245,3 @@ if (!setAll) {

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return false;
if (!key) return;
var storageType = getStorageType(options);

@@ -281,3 +266,3 @@ var removeAll = storageType === ALL;

if (removeAll || useGlobal(storageType)) {
globalContext[key] = undefined;
remove(key);
locations.push(GLOBAL);

@@ -294,3 +279,3 @@ }

function useGlobal(storage) {
return !storage || storage === GLOBAL;
return useType(storage, GLOBAL);
}

@@ -300,3 +285,3 @@

// If has localStorage and storage option not defined, or is set to 'localStorage' or '*'
return hasStorage && (!storage || storage === LOCAL_STORAGE || storage === ALL);
return hasStorage && useType(storage, LOCAL_STORAGE);
}

@@ -306,4 +291,8 @@

// If has cookies and storage option not defined, or is set to 'cookies' or '*'
return hasCookies && (!storage || storage === COOKIE || storage === ALL);
return hasCookiesSupport && useType(storage, COOKIE);
}
function useType(storage, type) {
return !storage || storage === type || storage === ALL;
}
var index = {

@@ -316,2 +305,2 @@ getItem: getItem,

export default index;
export { ALL, LOCAL_STORAGE, COOKIE, GLOBAL, getItem, setItem, removeItem, globalContext, hasLocalStorage as hasLocalStorageSupport };
export { ALL, LOCAL_STORAGE, COOKIE, GLOBAL, getItem, setItem, removeItem };

@@ -5,2 +5,4 @@ 'use strict';

var globalStorageUtils = require('@analytics/global-storage-utils');
var localstorageUtils = require('@analytics/localstorage-utils');
var cookieUtils = require('@analytics/cookie-utils');

@@ -71,20 +73,2 @@

function hasLocalStorage() {
return false;
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
localStorage.setItem('_t_', '1');
localStorage.removeItem('_t_');
} catch (err) {
return false;
}
return true;
}
function parse(input) {

@@ -118,4 +102,2 @@ var value;

var globalContext = (typeof self === "undefined" ? "undefined" : _typeof(self)) === 'object' && self.self === self && self || (typeof global === "undefined" ? "undefined" : _typeof(global)) === 'object' && global.global === global && global || undefined;
var ALL = '*';

@@ -126,4 +108,4 @@ var LOCAL_STORAGE = 'localStorage';

var hasStorage = hasLocalStorage();
var hasCookies = cookieUtils.hasCookieSupport();
var hasStorage = localstorageUtils.hasLocalStorage();
var hasCookiesSupport = cookieUtils.hasCookies();
/**

@@ -139,3 +121,3 @@ * Get storage item from localStorage, cookie, or window

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return null;
if (!key) return;
var storageType = getStorageType(options); // Get value from all locations

@@ -161,3 +143,3 @@

return globalContext[key] || null;
return globalStorageUtils.get(key);
}

@@ -169,3 +151,3 @@

localStorage: parse(localStorage.getItem(key)),
global: globalContext[key] || null
global: globalStorageUtils.get(key)
};

@@ -240,6 +222,6 @@ }

current: value,
previous: globalContext[key] // Set global value
previous: globalStorageUtils.get(key) // Set global value
};
globalContext[key] = value;
globalStorageUtils.set(key, value);

@@ -265,3 +247,3 @@ if (!setAll) {

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return false;
if (!key) return;
var storageType = getStorageType(options);

@@ -286,3 +268,3 @@ var removeAll = storageType === ALL;

if (removeAll || useGlobal(storageType)) {
globalContext[key] = undefined;
globalStorageUtils.remove(key);
locations.push(GLOBAL);

@@ -299,3 +281,3 @@ }

function useGlobal(storage) {
return !storage || storage === GLOBAL;
return useType(storage, GLOBAL);
}

@@ -305,3 +287,3 @@

// If has localStorage and storage option not defined, or is set to 'localStorage' or '*'
return hasStorage && (!storage || storage === LOCAL_STORAGE || storage === ALL);
return hasStorage && useType(storage, LOCAL_STORAGE);
}

@@ -311,4 +293,8 @@

// If has cookies and storage option not defined, or is set to 'cookies' or '*'
return hasCookies && (!storage || storage === COOKIE || storage === ALL);
return hasCookiesSupport && useType(storage, COOKIE);
}
function useType(storage, type) {
return !storage || storage === type || storage === ALL;
}
var index = {

@@ -320,6 +306,8 @@ getItem: getItem,

exports.globalContext = globalStorageUtils.globalContext;
exports.hasLocalStorage = localstorageUtils.hasLocalStorage;
exports.getCookie = cookieUtils.getCookie;
exports.setCookie = cookieUtils.setCookie;
exports.removeCookie = cookieUtils.removeCookie;
exports.hasCookieSupport = cookieUtils.hasCookieSupport;
exports.hasCookies = cookieUtils.hasCookies;
exports.ALL = ALL;

@@ -332,4 +320,2 @@ exports.LOCAL_STORAGE = LOCAL_STORAGE;

exports.removeItem = removeItem;
exports.globalContext = globalContext;
exports.hasLocalStorageSupport = hasLocalStorage;
exports.default = index;

@@ -1,3 +0,7 @@

import { hasCookieSupport, getCookie, setCookie, removeCookie } from '@analytics/cookie-utils';
export { getCookie, setCookie, removeCookie, hasCookieSupport } from '@analytics/cookie-utils';
import { get, set, remove } from '@analytics/global-storage-utils';
export { globalContext } from '@analytics/global-storage-utils';
import { hasLocalStorage } from '@analytics/localstorage-utils';
export { hasLocalStorage } from '@analytics/localstorage-utils';
import { hasCookies, getCookie, setCookie, removeCookie } from '@analytics/cookie-utils';
export { getCookie, setCookie, removeCookie, hasCookies } from '@analytics/cookie-utils';

@@ -67,20 +71,2 @@ function _typeof(obj) {

function hasLocalStorage() {
return false;
try {
if (typeof localStorage === 'undefined' || typeof JSON === 'undefined') {
return false;
} // test for safari private
localStorage.setItem('_t_', '1');
localStorage.removeItem('_t_');
} catch (err) {
return false;
}
return true;
}
function parse(input) {

@@ -114,4 +100,2 @@ var value;

var globalContext = (typeof self === "undefined" ? "undefined" : _typeof(self)) === 'object' && self.self === self && self || (typeof global === "undefined" ? "undefined" : _typeof(global)) === 'object' && global.global === global && global || undefined;
var ALL = '*';

@@ -123,3 +107,3 @@ var LOCAL_STORAGE = 'localStorage';

var hasStorage = hasLocalStorage();
var hasCookies = hasCookieSupport();
var hasCookiesSupport = hasCookies();
/**

@@ -135,3 +119,3 @@ * Get storage item from localStorage, cookie, or window

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return null;
if (!key) return;
var storageType = getStorageType(options); // Get value from all locations

@@ -157,3 +141,3 @@

return globalContext[key] || null;
return get(key);
}

@@ -165,3 +149,3 @@

localStorage: parse(localStorage.getItem(key)),
global: globalContext[key] || null
global: get(key)
};

@@ -236,6 +220,6 @@ }

current: value,
previous: globalContext[key] // Set global value
previous: get(key) // Set global value
};
globalContext[key] = value;
set(key, value);

@@ -261,3 +245,3 @@ if (!setAll) {

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return false;
if (!key) return;
var storageType = getStorageType(options);

@@ -282,3 +266,3 @@ var removeAll = storageType === ALL;

if (removeAll || useGlobal(storageType)) {
globalContext[key] = undefined;
remove(key);
locations.push(GLOBAL);

@@ -295,3 +279,3 @@ }

function useGlobal(storage) {
return !storage || storage === GLOBAL;
return useType(storage, GLOBAL);
}

@@ -301,3 +285,3 @@

// If has localStorage and storage option not defined, or is set to 'localStorage' or '*'
return hasStorage && (!storage || storage === LOCAL_STORAGE || storage === ALL);
return hasStorage && useType(storage, LOCAL_STORAGE);
}

@@ -307,4 +291,8 @@

// If has cookies and storage option not defined, or is set to 'cookies' or '*'
return hasCookies && (!storage || storage === COOKIE || storage === ALL);
return hasCookiesSupport && useType(storage, COOKIE);
}
function useType(storage, type) {
return !storage || storage === type || storage === ALL;
}
var index = {

@@ -317,2 +305,2 @@ getItem: getItem,

export default index;
export { ALL, LOCAL_STORAGE, COOKIE, GLOBAL, getItem, setItem, removeItem, globalContext, hasLocalStorage as hasLocalStorageSupport };
export { ALL, LOCAL_STORAGE, COOKIE, GLOBAL, getItem, setItem, removeItem };
{
"name": "@analytics/storage-utils",
"version": "0.2.5",
"version": "0.2.6",
"description": "Storage utilities for saving values in browser",

@@ -49,5 +49,7 @@ "author": "David Wells",

"dependencies": {
"@analytics/cookie-utils": "^0.2.3"
"@analytics/cookie-utils": "^0.2.4",
"@analytics/global-storage-utils": "^0.1.0",
"@analytics/localstorage-utils": "^0.1.2"
},
"gitHead": "54924261b60e44fa00841b8b3e740918d2e660c5"
"gitHead": "fc41263499919b5666630f1d76cc0844eae7370e"
}

@@ -32,3 +32,3 @@ <!--

setItem('key', 'value')
// returns { value: "value", oldValue: "old", location: "localStorage" }
// { value: "value", oldValue: "old", location: "localStorage" }

@@ -38,15 +38,12 @@ /** Setting values to specific location */

/* Set value to specifically localStorage */
setItem('key', 'otherValue', 'localStorage')
// setItem('key', 'otherValue', { storage: 'localStorage' })
// returns { value: "otherValue", oldValue: "value", location: "localStorage" }
setItem('key', 'otherValue', { storage: 'localStorage' })
// { value: "otherValue", oldValue: "value", location: "localStorage" }
/* Set value to specifically cookie */
setItem('keyTwo', 'cookieVal', 'cookie')
// setItem('keyTwo', 'cookieVal', { storage: 'cookie' })
// returns { value: "cookieVal", oldValue: "null", location: "cookie" }
setItem('keyTwo', 'cookieVal', { storage: 'cookie' })
// { value: "cookieVal", oldValue: "null", location: "cookie" }
/* Set value from specifically the global window (or global this in node.js) */
setItem('keyThree', 'xyz', 'global')
// setItem('keyThree', 'xyz', { storage: 'global' })
// returns { value: "cookieVal", oldValue: "null", location: "cookie" }
setItem('keyThree', 'xyz', { storage: 'global' })
// { value: "cookieVal", oldValue: "null", location: "cookie" }
```

@@ -68,19 +65,17 @@

/**
* Getting values to specific location
* Getting values to specific locations
*/
// Get value to specifically localStorage
const getLSValue = getItem('key', 'localStorage')
const getLocalStorageValue = getItem('key', { storage: 'localStorage' })
/* Get value to specifically cookie */
const getLSValue = getItem('key', 'cookie')
// getItem('key', { storage: 'cookie' })
const getCookieValue = getItem('key', { storage: 'cookie' })
/* Get value from specifically the global window (or global this in node.js) */
const getLSValue = getItem('key', 'global')
// getItem('key', { storage: 'global' })
const getGlobalValue = getItem('key', { storage: 'global' })
/* Get value from all locations */
const valueObj = getItem('otherKey', '*')
// returns { cookie: undefined, localStorage: "hahaha", global: null }
const valueObj = getItem('otherKey', { storage: '*' })
// { cookie: undefined, localStorage: "hahaha", global: null }
```

@@ -100,15 +95,15 @@

/** Removing values to specific location */
/** Removing values to specific locations */
/* Remove value to specifically localStorage */
removeItem('key', 'localStorage')
// removeItem('key', { storage: 'localStorage' })
removeItem('key', { storage: 'localStorage' })
/* Remove value to specifically cookie */
removeItem('keyTwo', 'cookie')
// removeItem('keyTwo', { storage: 'cookie' })
removeItem('keyTwo', { storage: 'cookie' })
/* Remove value to specifically global */
removeItem('keyThree', 'global')
// removeItem('keyThree', { storage: 'global' })
removeItem('keyThree', { storage: 'global' })
/* Remove value from all locations */
removeItem('otherKey', { storage: '*' })
```
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