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

analytics-utils

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

analytics-utils - npm Package Compare versions

Comparing version 0.0.16 to 0.0.17

86

dist/analytics-utils.js

@@ -530,2 +530,29 @@ var analyticsUtils = (function (exports) {

// const context = (typeof self === 'object' && self.self === self && self) || // eslint-disable-line
// (typeof global === 'object' && global.global === global && global) ||
// this
//
// export default context
var getGlobal = function getGlobal() {
if (typeof self !== 'undefined' && self) {
return self;
}
/* istanbul ignore next */
if (typeof window !== 'undefined' && window) {
return window;
}
if (typeof global !== 'undefined' && global) {
return global;
}
if (typeof globalThis !== 'undefined' && globalThis) {
return globalThis;
}
};
var globalContext = getGlobal();
var hasLocalStorage$1 = hasLocalStorage();

@@ -540,6 +567,7 @@ /**

function getItem(key, opts) {
if (!isInBrowser || !key) return false;
var options = opts || {};
var storage = options.storage; // Try localStorage
function getItem(key) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return null;
var storage = options.storage;
/* 1. Try localStorage */

@@ -549,3 +577,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

if (value || storage === 'localStorage') return parse(value);
} // Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -557,6 +586,7 @@

if (_value || storage === 'cookie') return parse(_value);
} // Fallback to window
}
/* 3. Fallback to window/global. TODO verify AWS lambda & check for conflicts */
return window[key] || null;
return globalContext[key] || null;
}

@@ -571,7 +601,8 @@ /**

function setItem(key, value, opts) {
if (!isInBrowser || !key || !value) return false;
function setItem(key, value) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (!key || !value) return false;
var storage = options.storage;
var saveValue = JSON.stringify(value);
var options = opts || {};
var storage = options.storage; // 1. Try localStorage
/* 1. Try localStorage */

@@ -588,3 +619,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

};
} // 2. Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -602,8 +634,9 @@

};
} // 3. Fallback to window
}
/* 3. Fallback to window/global */
var oldValue = window[key]; // console.log('SET as window', value)
var oldValue = globalContext[key]; // console.log('SET as window', value)
window[key] = value;
globalContext[key] = value;
return {

@@ -622,6 +655,7 @@ value: value,

function removeItem(key, opts) {
if (!isInBrowser || !key) return false;
var options = opts || {};
var storage = options.storage; // 1. Try localStorage
function removeItem(key) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return false;
var storage = options.storage;
/* 1. Try localStorage */

@@ -631,3 +665,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

return null;
} // 2. Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -638,9 +673,9 @@

return null;
} // 3. Fallback to window
}
/* 3. Fallback to window/global */
window[key] = null;
globalContext[key] = null;
return null;
} //*
}
var index = {

@@ -650,4 +685,2 @@ getItem: getItem,

removeItem: removeItem
/**/
};

@@ -690,2 +723,3 @@

exports.uuid = uuid;
exports.globalContext = globalContext;

@@ -692,0 +726,0 @@ return exports;

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

var analyticsUtils=function(e){"use strict";var u="undefined"!=typeof window;var l=function(){try{if(!u)return!1;document.cookie="cookietest=1";var e=-1!==document.cookie.indexOf("cookietest=");return document.cookie="cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT",e}catch(e){return!1}}();function s(e,t,r){if(!l)return!1;var n="";if(r){var o=new Date;o.setTime(o.getTime()+24*r*60*60*1e3),n="; expires=".concat(o.toGMTString())}document.cookie="".concat(e,"=").concat(t).concat(n,"; path=/")}function m(e){if(!l)return!1;for(var t="".concat(e,"="),r=document.cookie.split(";"),n=0;n<r.length;n++){for(var o=r[n];" "===o.charAt(0);)o=o.substring(1,o.length);if(0===o.indexOf(t))return o.substring(t.length,o.length)}return null}function n(e){if(!l)return!1;s(e,"",-1)}var t={getCookie:m,setCookie:s,removeCookie:n};function f(e){return decodeURIComponent(e).replace(/\+/g," ")}function g(e){if(!u)return!1;var t=e||document.referrer;if(t){var r=window.document.location.port,n=t.split("/")[2];return r&&(n=n.replace(":".concat(r),"")),n!==window.location.hostname}return!1}function c(e,t){var r=(e.split("?")||[,])[1];if(!r||-1===r.indexOf(t))return e;var n=new RegExp("(\\&|\\?)".concat(t,"([_A-Za-z0-9=.%]+)"),"g"),o="?".concat(r).replace(n,"").replace(/^&/,"?");return e.replace("?".concat(r),o)}function i(e){var t=function(e){if(e){var t=e.match(/\?(.*)/);return t&&t[1]?t[1].split("#")[0]:""}return u&&window.location.search.substring(1)}(e);return t?function(e){var t,r=/([^&=]+)=?([^&]*)/g,n={};for(;t=r.exec(e);){var o=f(t[1]),a=f(t[2]);if("[]"===o.substring(o.length-2))o=o.substring(0,o.length-2),(n[o]||(n[o]=[])).push(a);else{var c=""===a||a;n[o]=c}}for(var i in n){var u=i.split("[");if(1<u.length){var l=[];u.forEach(function(e,t){var r=e.replace(/[?[\]\\ ]/g,"");l.push(r)}),p(n,l,n[i]),delete n[i]}}return n}(t):{}}function p(e,t,r){for(var n=t.length-1,o=0;o<n;++o){var a=t[o];a in e||(e[a]={}),e=e[a]}e[t[n]]=r}function r(e){if(!u)return null;var t=document.createElement("a");return t.setAttribute("href",e),t.hostname}function d(e){return(r(e)||"").split(".").slice(-2).join(".")}function v(e){var t=e.split(".");return 1<t.length?t.slice(0,-1).join("."):e}var o={trimTld:v,getDomainBase:d,getDomainHost:r};var h={"daum.net":"q","eniro.se":"search_word","naver.com":"query","yahoo.com":"p","msn.com":"q","aol.com":"q","lycos.com":"q","ask.com":"q","altavista.com":"q","cnn.com":"query","about.com":"terms","alltheweb.com":"q","voila.fr":"rdata","baidu.com":"wd","alice.com":"qs","yandex.com":"text","seznam.cz":"q","search.com":"q","szukacz.pl":"q","yam.com":"k","pchome.com":"q","kvasir.no":"q","sesam.no":"q","ozu.es":"q","terra.com":"query","mynet.com":"q","ekolay.net":"q","rambler.ru":"words",google:"q","wp.pl":{p:"szukaj ",n:"wirtulana polska"},"online.onetcenter.org":{p:"qt",n:"o*net"},"najdi.org.mk":{p:"q",n:"najdi"},"search.virgilio.it":{p:"qs",n:"virgilio"},"mamma.com":{p:"query",n:"mama"},"search.netscape.com":{p:"query",n:"netscape"},"bing.com":{p:"q",n:"live"}};function a(e){return(a="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 y(t){var r;try{void 0===(r=JSON.parse(t))&&(r=t),"true"===r&&(r=!0),"false"===r&&(r=!1),parseFloat(r)===r&&"object"!==a(r)&&(r=parseFloat(r))}catch(e){r=t}return r}var w=function(){try{if("undefined"==typeof localStorage||"undefined"==typeof JSON)return!1;localStorage.setItem("_test_","1"),localStorage.removeItem("_test_")}catch(e){return!1}return!0}();var k={getItem:function(e,t){if(!u||!e)return!1;var r=(t||{}).storage;if(w&&(!r||"localStorage"===r)){var n=localStorage.getItem(e);if(n||"localStorage"===r)return y(n)}if(l&&(!r||"cookie"===r)){var o=m(e);if(o||"cookie"===r)return y(o)}return window[e]||null},setItem:function(e,t,r){if(!u||!e||!t)return!1;var n=JSON.stringify(t),o=(r||{}).storage;if(w&&(!o||"localStorage"===o)){var a=y(localStorage.getItem(e));return localStorage.setItem(e,n),{value:t,oldValue:a,type:"localStorage"}}if(l&&(!o||"cookie"===o)){var c=y(m(e));return s(e,n),{value:t,oldValue:c,type:"cookie"}}var i=window[e];return{value:window[e]=t,oldValue:i,type:"window"}},removeItem:function(e,t){if(!u||!e)return!1;var r=(t||{}).storage;return!w||r&&"localStorage"!==r?!l||r&&"cookie"!==r?window[e]=null:(n(e),null):(localStorage.removeItem(e),null)}};return e.cookie=t,e.decodeUri=f,e.getBrowserLocale=function(){if(!u)return null;var e=navigator,t=e.language,r=e.languages,n=e.userLanguage;return r&&r.length?r[0]:n||t},e.getTimeZone=function(){return"undefined"==typeof Intl||"function"!=typeof Intl.DateTimeFormat||"function"!=typeof Intl.DateTimeFormat().resolvedOptions?null:Intl.DateTimeFormat().resolvedOptions().timeZone},e.inBrowser=u,e.isExternalReferrer=g,e.isScriptLoaded=function(r){if(!u)return!0;var n=document.getElementsByTagName("script");return!!Object.keys(n).filter(function(e){var t=n[e].src;return"string"==typeof r?-1!==t.indexOf(r):r instanceof RegExp&&t.match(r)}).length},e.noOp=function(){},e.paramsClean=c,e.paramsGet=function(e,t){return f((RegExp("".concat(e,"=(.+?)(&|$)")).exec(t)||[,""])[1])},e.paramsParse=i,e.paramsRemove=function(o,a){return new Promise(function(e,t){if(u&&window.history&&window.history.replaceState){var r=window.location.href,n=c(r,o);r!==n&&history.replaceState({},"",n)}return a&&a(),e()})},e.parseReferrer=function(e,t){if(!u)return!1;var r={source:"(direct)",medium:"(none)",campaign:"(not set)"};e&&g(e)&&(r.referrer=e);var n=function(e){if(!e||!u)return!1;var t=d(e),r=document.createElement("a");if(r.href=e,-1<r.hostname.indexOf("google")&&(t="google"),h[t]){var n=h[t],o="string"==typeof n?n:n.p,a=new RegExp(o+"=.*?([^&#]*|$)","gi"),c=r.search.match(a);return{source:n.n||v(t),medium:"organic",term:(c?c[0].split("=")[1]:"")||"(not provided)"}}var i=g(e)?"referral":"internal";return{source:r.hostname,medium:i}}(e);n&&Object.keys(n).length&&(r=Object.assign({},r,n));var o=i(t),a=Object.keys(o);if(a.length){var c=a.reduce(function(e,t){return t.match(/^utm_/)&&(e["".concat(t.replace(/^utm_/,""))]=o[t]),t.match(/^(d|g)clid/)&&(e.source="google",e.medium=o.gclid?"cpc":"cpm",e[t]=o[t]),e},{});r=Object.assign({},r,c),(o.dclid||o.gclid)&&(r.source="google",r.medium=o.gclid?"cpc":"cpm")}return r},e.storage=k,e.url=o,e.uuid=function(){for(var e,t,r,n,o=[],a=0;a<256;a++)o[a]=(a<16?"0":"")+a.toString(16);return e=4294967295*Math.random()|0,t=4294967295*Math.random()|0,r=4294967295*Math.random()|0,n=4294967295*Math.random()|0,"".concat(o[255&e]+o[e>>8&255]+o[e>>16&255]+o[e>>24&255],"-").concat(o[255&t]).concat(o[t>>8&255],"-").concat(o[t>>16&15|64]).concat(o[t>>24&255],"-").concat(o[63&r|128]).concat(o[r>>8&255],"-").concat(o[r>>16&255]).concat(o[r>>24&255]).concat(o[255&n]).concat(o[n>>8&255]).concat(o[n>>16&255]).concat(o[n>>24&255])},e}({});
var analyticsUtils=function(e){"use strict";var u="undefined"!=typeof window;var l=function(){try{if(!u)return!1;document.cookie="cookietest=1";var e=-1!==document.cookie.indexOf("cookietest=");return document.cookie="cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT",e}catch(e){return!1}}();function s(e,t,n){if(!l)return!1;var r="";if(n){var o=new Date;o.setTime(o.getTime()+24*n*60*60*1e3),r="; expires=".concat(o.toGMTString())}document.cookie="".concat(e,"=").concat(t).concat(r,"; path=/")}function f(e){if(!l)return!1;for(var t="".concat(e,"="),n=document.cookie.split(";"),r=0;r<n.length;r++){for(var o=n[r];" "===o.charAt(0);)o=o.substring(1,o.length);if(0===o.indexOf(t))return o.substring(t.length,o.length)}return null}function r(e){if(!l)return!1;s(e,"",-1)}var t={getCookie:f,setCookie:s,removeCookie:r};function m(e){return decodeURIComponent(e).replace(/\+/g," ")}function g(e){if(!u)return!1;var t=e||document.referrer;if(t){var n=window.document.location.port,r=t.split("/")[2];return n&&(r=r.replace(":".concat(n),"")),r!==window.location.hostname}return!1}function c(e,t){var n=(e.split("?")||[,])[1];if(!n||-1===n.indexOf(t))return e;var r=new RegExp("(\\&|\\?)".concat(t,"([_A-Za-z0-9=.%]+)"),"g"),o="?".concat(n).replace(r,"").replace(/^&/,"?");return e.replace("?".concat(n),o)}function i(e){var t=function(e){if(e){var t=e.match(/\?(.*)/);return t&&t[1]?t[1].split("#")[0]:""}return u&&window.location.search.substring(1)}(e);return t?function(e){var t,n=/([^&=]+)=?([^&]*)/g,r={};for(;t=n.exec(e);){var o=m(t[1]),a=m(t[2]);if("[]"===o.substring(o.length-2))o=o.substring(0,o.length-2),(r[o]||(r[o]=[])).push(a);else{var c=""===a||a;r[o]=c}}for(var i in r){var u=i.split("[");if(1<u.length){var l=[];u.forEach(function(e,t){var n=e.replace(/[?[\]\\ ]/g,"");l.push(n)}),d(r,l,r[i]),delete r[i]}}return r}(t):{}}function d(e,t,n){for(var r=t.length-1,o=0;o<r;++o){var a=t[o];a in e||(e[a]={}),e=e[a]}e[t[r]]=n}function n(e){if(!u)return null;var t=document.createElement("a");return t.setAttribute("href",e),t.hostname}function p(e){return(n(e)||"").split(".").slice(-2).join(".")}function v(e){var t=e.split(".");return 1<t.length?t.slice(0,-1).join("."):e}var o={trimTld:v,getDomainBase:p,getDomainHost:n};var h={"daum.net":"q","eniro.se":"search_word","naver.com":"query","yahoo.com":"p","msn.com":"q","aol.com":"q","lycos.com":"q","ask.com":"q","altavista.com":"q","cnn.com":"query","about.com":"terms","alltheweb.com":"q","voila.fr":"rdata","baidu.com":"wd","alice.com":"qs","yandex.com":"text","seznam.cz":"q","search.com":"q","szukacz.pl":"q","yam.com":"k","pchome.com":"q","kvasir.no":"q","sesam.no":"q","ozu.es":"q","terra.com":"query","mynet.com":"q","ekolay.net":"q","rambler.ru":"words",google:"q","wp.pl":{p:"szukaj ",n:"wirtulana polska"},"online.onetcenter.org":{p:"qt",n:"o*net"},"najdi.org.mk":{p:"q",n:"najdi"},"search.virgilio.it":{p:"qs",n:"virgilio"},"mamma.com":{p:"query",n:"mama"},"search.netscape.com":{p:"query",n:"netscape"},"bing.com":{p:"q",n:"live"}};function a(e){return(a="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 y(t){var n;try{void 0===(n=JSON.parse(t))&&(n=t),"true"===n&&(n=!0),"false"===n&&(n=!1),parseFloat(n)===n&&"object"!==a(n)&&(n=parseFloat(n))}catch(e){n=t}return n}var w="undefined"!=typeof self&&self?self:"undefined"!=typeof window&&window?window:"undefined"!=typeof global&&global?global:"undefined"!=typeof globalThis&&globalThis?globalThis:void 0,b=function(){try{if("undefined"==typeof localStorage||"undefined"==typeof JSON)return!1;localStorage.setItem("_test_","1"),localStorage.removeItem("_test_")}catch(e){return!1}return!0}();var k={getItem:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(!e)return null;var n=t.storage;if(b&&(!n||"localStorage"===n)){var r=localStorage.getItem(e);if(r||"localStorage"===n)return y(r)}if(l&&(!n||"cookie"===n)){var o=f(e);if(o||"cookie"===n)return y(o)}return w[e]||null},setItem:function(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(!e||!t)return!1;var r=n.storage,o=JSON.stringify(t);if(b&&(!r||"localStorage"===r)){var a=y(localStorage.getItem(e));return localStorage.setItem(e,o),{value:t,oldValue:a,type:"localStorage"}}if(l&&(!r||"cookie"===r)){var c=y(f(e));return s(e,o),{value:t,oldValue:c,type:"cookie"}}var i=w[e];return{value:w[e]=t,oldValue:i,type:"window"}},removeItem:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(!e)return!1;var n=t.storage;return!b||n&&"localStorage"!==n?!l||n&&"cookie"!==n?w[e]=null:(r(e),null):(localStorage.removeItem(e),null)}};return e.cookie=t,e.decodeUri=m,e.getBrowserLocale=function(){if(!u)return null;var e=navigator,t=e.language,n=e.languages,r=e.userLanguage;return n&&n.length?n[0]:r||t},e.getTimeZone=function(){return"undefined"==typeof Intl||"function"!=typeof Intl.DateTimeFormat||"function"!=typeof Intl.DateTimeFormat().resolvedOptions?null:Intl.DateTimeFormat().resolvedOptions().timeZone},e.inBrowser=u,e.isExternalReferrer=g,e.isScriptLoaded=function(n){if(!u)return!0;var r=document.getElementsByTagName("script");return!!Object.keys(r).filter(function(e){var t=r[e].src;return"string"==typeof n?-1!==t.indexOf(n):n instanceof RegExp&&t.match(n)}).length},e.noOp=function(){},e.paramsClean=c,e.paramsGet=function(e,t){return m((RegExp("".concat(e,"=(.+?)(&|$)")).exec(t)||[,""])[1])},e.paramsParse=i,e.paramsRemove=function(o,a){return new Promise(function(e,t){if(u&&window.history&&window.history.replaceState){var n=window.location.href,r=c(n,o);n!==r&&history.replaceState({},"",r)}return a&&a(),e()})},e.parseReferrer=function(e,t){if(!u)return!1;var n={source:"(direct)",medium:"(none)",campaign:"(not set)"};e&&g(e)&&(n.referrer=e);var r=function(e){if(!e||!u)return!1;var t=p(e),n=document.createElement("a");if(n.href=e,-1<n.hostname.indexOf("google")&&(t="google"),h[t]){var r=h[t],o="string"==typeof r?r:r.p,a=new RegExp(o+"=.*?([^&#]*|$)","gi"),c=n.search.match(a);return{source:r.n||v(t),medium:"organic",term:(c?c[0].split("=")[1]:"")||"(not provided)"}}var i=g(e)?"referral":"internal";return{source:n.hostname,medium:i}}(e);r&&Object.keys(r).length&&(n=Object.assign({},n,r));var o=i(t),a=Object.keys(o);if(a.length){var c=a.reduce(function(e,t){return t.match(/^utm_/)&&(e["".concat(t.replace(/^utm_/,""))]=o[t]),t.match(/^(d|g)clid/)&&(e.source="google",e.medium=o.gclid?"cpc":"cpm",e[t]=o[t]),e},{});n=Object.assign({},n,c),(o.dclid||o.gclid)&&(n.source="google",n.medium=o.gclid?"cpc":"cpm")}return n},e.storage=k,e.url=o,e.uuid=function(){for(var e,t,n,r,o=[],a=0;a<256;a++)o[a]=(a<16?"0":"")+a.toString(16);return e=4294967295*Math.random()|0,t=4294967295*Math.random()|0,n=4294967295*Math.random()|0,r=4294967295*Math.random()|0,"".concat(o[255&e]+o[e>>8&255]+o[e>>16&255]+o[e>>24&255],"-").concat(o[255&t]).concat(o[t>>8&255],"-").concat(o[t>>16&15|64]).concat(o[t>>24&255],"-").concat(o[63&n|128]).concat(o[n>>8&255],"-").concat(o[n>>16&255]).concat(o[n>>24&255]).concat(o[255&r]).concat(o[r>>8&255]).concat(o[r>>16&255]).concat(o[r>>24&255])},e.globalContext=w,e}({});

@@ -531,2 +531,29 @@ 'use strict';

// const context = (typeof self === 'object' && self.self === self && self) || // eslint-disable-line
// (typeof global === 'object' && global.global === global && global) ||
// this
//
// export default context
var getGlobal = function getGlobal() {
if (typeof self !== 'undefined' && self) {
return self;
}
/* istanbul ignore next */
if (typeof window !== 'undefined' && window) {
return window;
}
if (typeof global !== 'undefined' && global) {
return global;
}
if (typeof globalThis !== 'undefined' && globalThis) {
return globalThis;
}
};
var globalContext = getGlobal();
var hasLocalStorage$1 = hasLocalStorage();

@@ -541,6 +568,7 @@ /**

function getItem(key, opts) {
if (!isInBrowser || !key) return false;
var options = opts || {};
var storage = options.storage; // Try localStorage
function getItem(key) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return null;
var storage = options.storage;
/* 1. Try localStorage */

@@ -550,3 +578,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

if (value || storage === 'localStorage') return parse(value);
} // Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -558,6 +587,7 @@

if (_value || storage === 'cookie') return parse(_value);
} // Fallback to window
}
/* 3. Fallback to window/global. TODO verify AWS lambda & check for conflicts */
return window[key] || null;
return globalContext[key] || null;
}

@@ -572,7 +602,8 @@ /**

function setItem(key, value, opts) {
if (!isInBrowser || !key || !value) return false;
function setItem(key, value) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (!key || !value) return false;
var storage = options.storage;
var saveValue = JSON.stringify(value);
var options = opts || {};
var storage = options.storage; // 1. Try localStorage
/* 1. Try localStorage */

@@ -589,3 +620,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

};
} // 2. Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -603,8 +635,9 @@

};
} // 3. Fallback to window
}
/* 3. Fallback to window/global */
var oldValue = window[key]; // console.log('SET as window', value)
var oldValue = globalContext[key]; // console.log('SET as window', value)
window[key] = value;
globalContext[key] = value;
return {

@@ -623,6 +656,7 @@ value: value,

function removeItem(key, opts) {
if (!isInBrowser || !key) return false;
var options = opts || {};
var storage = options.storage; // 1. Try localStorage
function removeItem(key) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return false;
var storage = options.storage;
/* 1. Try localStorage */

@@ -632,3 +666,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

return null;
} // 2. Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -639,9 +674,9 @@

return null;
} // 3. Fallback to window
}
/* 3. Fallback to window/global */
window[key] = null;
globalContext[key] = null;
return null;
} //*
}
var index = {

@@ -651,4 +686,2 @@ getItem: getItem,

removeItem: removeItem
/**/
};

@@ -691,1 +724,2 @@

exports.uuid = uuid;
exports.globalContext = globalContext;

@@ -527,2 +527,29 @@ var isInBrowser = typeof window !== 'undefined';

// const context = (typeof self === 'object' && self.self === self && self) || // eslint-disable-line
// (typeof global === 'object' && global.global === global && global) ||
// this
//
// export default context
var getGlobal = function getGlobal() {
if (typeof self !== 'undefined' && self) {
return self;
}
/* istanbul ignore next */
if (typeof window !== 'undefined' && window) {
return window;
}
if (typeof global !== 'undefined' && global) {
return global;
}
if (typeof globalThis !== 'undefined' && globalThis) {
return globalThis;
}
};
var globalContext = getGlobal();
var hasLocalStorage$1 = hasLocalStorage();

@@ -537,6 +564,7 @@ /**

function getItem(key, opts) {
if (!isInBrowser || !key) return false;
var options = opts || {};
var storage = options.storage; // Try localStorage
function getItem(key) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return null;
var storage = options.storage;
/* 1. Try localStorage */

@@ -546,3 +574,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

if (value || storage === 'localStorage') return parse(value);
} // Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -554,6 +583,7 @@

if (_value || storage === 'cookie') return parse(_value);
} // Fallback to window
}
/* 3. Fallback to window/global. TODO verify AWS lambda & check for conflicts */
return window[key] || null;
return globalContext[key] || null;
}

@@ -568,7 +598,8 @@ /**

function setItem(key, value, opts) {
if (!isInBrowser || !key || !value) return false;
function setItem(key, value) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (!key || !value) return false;
var storage = options.storage;
var saveValue = JSON.stringify(value);
var options = opts || {};
var storage = options.storage; // 1. Try localStorage
/* 1. Try localStorage */

@@ -585,3 +616,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

};
} // 2. Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -599,8 +631,9 @@

};
} // 3. Fallback to window
}
/* 3. Fallback to window/global */
var oldValue = window[key]; // console.log('SET as window', value)
var oldValue = globalContext[key]; // console.log('SET as window', value)
window[key] = value;
globalContext[key] = value;
return {

@@ -619,6 +652,7 @@ value: value,

function removeItem(key, opts) {
if (!isInBrowser || !key) return false;
var options = opts || {};
var storage = options.storage; // 1. Try localStorage
function removeItem(key) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return false;
var storage = options.storage;
/* 1. Try localStorage */

@@ -628,3 +662,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

return null;
} // 2. Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -635,9 +670,9 @@

return null;
} // 3. Fallback to window
}
/* 3. Fallback to window/global */
window[key] = null;
globalContext[key] = null;
return null;
} //*
}
var index = {

@@ -647,4 +682,2 @@ getItem: getItem,

removeItem: removeItem
/**/
};

@@ -671,2 +704,2 @@

export { cookie, decode as decodeUri, getBrowserLocale, getTimeZone, isInBrowser as inBrowser, isExternalReferrer, isScriptLoaded, noOp, paramsClean, getValueParamValue as paramsGet, paramsParse, paramsRemove, parseReferrer, index as storage, url, uuid };
export { cookie, decode as decodeUri, getBrowserLocale, getTimeZone, isInBrowser as inBrowser, isExternalReferrer, isScriptLoaded, noOp, paramsClean, getValueParamValue as paramsGet, paramsParse, paramsRemove, parseReferrer, index as storage, url, uuid, globalContext };

@@ -531,2 +531,29 @@ 'use strict';

// const context = (typeof self === 'object' && self.self === self && self) || // eslint-disable-line
// (typeof global === 'object' && global.global === global && global) ||
// this
//
// export default context
var getGlobal = function getGlobal() {
if (typeof self !== 'undefined' && self) {
return self;
}
/* istanbul ignore next */
if (typeof window !== 'undefined' && window) {
return window;
}
if (typeof global !== 'undefined' && global) {
return global;
}
if (typeof globalThis !== 'undefined' && globalThis) {
return globalThis;
}
};
var globalContext = getGlobal();
var hasLocalStorage$1 = hasLocalStorage();

@@ -541,6 +568,7 @@ /**

function getItem(key, opts) {
if (!isInBrowser || !key) return false;
var options = opts || {};
var storage = options.storage; // Try localStorage
function getItem(key) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return null;
var storage = options.storage;
/* 1. Try localStorage */

@@ -550,3 +578,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

if (value || storage === 'localStorage') return parse(value);
} // Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -558,6 +587,7 @@

if (_value || storage === 'cookie') return parse(_value);
} // Fallback to window
}
/* 3. Fallback to window/global. TODO verify AWS lambda & check for conflicts */
return window[key] || null;
return globalContext[key] || null;
}

@@ -572,7 +602,8 @@ /**

function setItem(key, value, opts) {
if (!isInBrowser || !key || !value) return false;
function setItem(key, value) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (!key || !value) return false;
var storage = options.storage;
var saveValue = JSON.stringify(value);
var options = opts || {};
var storage = options.storage; // 1. Try localStorage
/* 1. Try localStorage */

@@ -589,3 +620,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

};
} // 2. Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -603,8 +635,9 @@

};
} // 3. Fallback to window
}
/* 3. Fallback to window/global */
var oldValue = window[key]; // console.log('SET as window', value)
var oldValue = globalContext[key]; // console.log('SET as window', value)
window[key] = value;
globalContext[key] = value;
return {

@@ -623,6 +656,7 @@ value: value,

function removeItem(key, opts) {
if (!isInBrowser || !key) return false;
var options = opts || {};
var storage = options.storage; // 1. Try localStorage
function removeItem(key) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return false;
var storage = options.storage;
/* 1. Try localStorage */

@@ -632,3 +666,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

return null;
} // 2. Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -639,9 +674,9 @@

return null;
} // 3. Fallback to window
}
/* 3. Fallback to window/global */
window[key] = null;
globalContext[key] = null;
return null;
} //*
}
var index = {

@@ -651,4 +686,2 @@ getItem: getItem,

removeItem: removeItem
/**/
};

@@ -691,1 +724,2 @@

exports.uuid = uuid;
exports.globalContext = globalContext;

@@ -527,2 +527,29 @@ var isInBrowser = typeof window !== 'undefined';

// const context = (typeof self === 'object' && self.self === self && self) || // eslint-disable-line
// (typeof global === 'object' && global.global === global && global) ||
// this
//
// export default context
var getGlobal = function getGlobal() {
if (typeof self !== 'undefined' && self) {
return self;
}
/* istanbul ignore next */
if (typeof window !== 'undefined' && window) {
return window;
}
if (typeof global !== 'undefined' && global) {
return global;
}
if (typeof globalThis !== 'undefined' && globalThis) {
return globalThis;
}
};
var globalContext = getGlobal();
var hasLocalStorage$1 = hasLocalStorage();

@@ -537,6 +564,7 @@ /**

function getItem(key, opts) {
if (!isInBrowser || !key) return false;
var options = opts || {};
var storage = options.storage; // Try localStorage
function getItem(key) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return null;
var storage = options.storage;
/* 1. Try localStorage */

@@ -546,3 +574,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

if (value || storage === 'localStorage') return parse(value);
} // Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -554,6 +583,7 @@

if (_value || storage === 'cookie') return parse(_value);
} // Fallback to window
}
/* 3. Fallback to window/global. TODO verify AWS lambda & check for conflicts */
return window[key] || null;
return globalContext[key] || null;
}

@@ -568,7 +598,8 @@ /**

function setItem(key, value, opts) {
if (!isInBrowser || !key || !value) return false;
function setItem(key, value) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (!key || !value) return false;
var storage = options.storage;
var saveValue = JSON.stringify(value);
var options = opts || {};
var storage = options.storage; // 1. Try localStorage
/* 1. Try localStorage */

@@ -585,3 +616,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

};
} // 2. Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -599,8 +631,9 @@

};
} // 3. Fallback to window
}
/* 3. Fallback to window/global */
var oldValue = window[key]; // console.log('SET as window', value)
var oldValue = globalContext[key]; // console.log('SET as window', value)
window[key] = value;
globalContext[key] = value;
return {

@@ -619,6 +652,7 @@ value: value,

function removeItem(key, opts) {
if (!isInBrowser || !key) return false;
var options = opts || {};
var storage = options.storage; // 1. Try localStorage
function removeItem(key) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!key) return false;
var storage = options.storage;
/* 1. Try localStorage */

@@ -628,3 +662,4 @@ if (hasLocalStorage$1 && (!storage || storage === 'localStorage')) {

return null;
} // 2. Fallback to cookie
}
/* 2. Fallback to cookie */

@@ -635,9 +670,9 @@

return null;
} // 3. Fallback to window
}
/* 3. Fallback to window/global */
window[key] = null;
globalContext[key] = null;
return null;
} //*
}
var index = {

@@ -647,4 +682,2 @@ getItem: getItem,

removeItem: removeItem
/**/
};

@@ -671,2 +704,2 @@

export { cookie, decode as decodeUri, getBrowserLocale, getTimeZone, isInBrowser as inBrowser, isExternalReferrer, isScriptLoaded, noOp, paramsClean, getValueParamValue as paramsGet, paramsParse, paramsRemove, parseReferrer, index as storage, url, uuid };
export { cookie, decode as decodeUri, getBrowserLocale, getTimeZone, isInBrowser as inBrowser, isExternalReferrer, isScriptLoaded, noOp, paramsClean, getValueParamValue as paramsGet, paramsParse, paramsRemove, parseReferrer, index as storage, url, uuid, globalContext };
{
"name": "analytics-utils",
"version": "0.0.16",
"version": "0.0.17",
"description": "Analytics utility functions",

@@ -57,3 +57,3 @@ "author": "David Wells <hello@davidwells.io>",

},
"gitHead": "d4a3a1abd696728911b84d8d9a3239c432362397"
"gitHead": "d7926a362de35c94e21cbd0e9f1d9cdf63f76791"
}
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