google-optimize-service
Advanced tools
Comparing version 1.1.18 to 1.1.19
@@ -1,3 +0,3 @@ | ||
// https://github.com/haensl/google-optimize-service#readme v1.1.18 Copyright 2022 HP Dietz | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("querystring"));const t={localStorage:"local",sessionStorage:"session"},o={autopersist:!0,fields:["variant"],key:"optimize",location:{search:""},storage:null,storagePreference:t.localStorage},s=e=>{if(Array.isArray(e)&&e.reduce(((e,r)=>e&&"string"==typeof r),!0))o.fields=e.slice();else if(e)throw new TypeError("Invalid parameter. Expected newFields to be Array of strings.");return o.fields.slice()},n=e=>{if("boolean"==typeof e)o.autopersist=e;else if(void 0!==e)throw new TypeError("Invalid parameter. Expected shouldAutopersist to be boolean.");return o.autopersist},i=e=>{if("string"==typeof e)o.key=e;else if(e)throw new TypeError("Invalid parameter. Expected newKey to be string");return o.key},a=e=>{if(e){if(!("search"in e)||"string"!=typeof e.search)throw new TypeError('Invalid parameter. Expected newLocation to be object with string property "serach".');o.location=e}return{search:o.location.search}},c=e=>{if(e){if("object"!=typeof e)throw new TypeError("Invalid parameter. Expected storage to be object.");["getItem","setItem"].forEach((r=>{if("function"!=typeof e[r])throw new TypeError(`Invalid parameter. Expected storage to implement function ${r}.`)})),o.storage=e}return Object.assign({},o.storage)},l=e=>{if(e){if(!Object.values(t).includes(e))throw new TypeError(`Invalid parameter. Expected newStoragePreference to be on of ${Object.values(t).join(", ")}.`);o.storagePreference=e}return o.storagePreference},p=e=>{if("object"!=typeof e)throw new TypeError("Invalid parameter. Expected opts to be object.");Object.keys(o).forEach((r=>{if(r in e)try{switch(r){case"autopersist":n(e.autopersist);break;case"key":i(e.key);break;case"location":a(e.location);break;case"storage":c(e.storage);break;case"storagePreference":l(e.storagePreference);break;case"fields":s(e.fields)}}catch(e){throw new TypeError(`Invalid option: ${r}.`,e.message)}}))},f=()=>{const e={};if(o.location){const t=r.default.parse(o.location.search.replace(/^\?/,""));"utm_expid"in t&&(e.experimentId=t.utm_expid),"utm_referrer"in t&&(e.referrer=t.utm_referrer),(o.fields||[]).forEach((r=>{r in t&&(e[r]=t[r])}))}return Object.keys(e).length?e:null},d=(e=u())=>{o.storage&&o.storage.setItem(o.key,JSON.stringify(e))},g=()=>{if(o.location){const e=f();if(e)return e.experimentId}},u=(e=g())=>{const r=(()=>{if(o.storage){const e=o.storage.getItem(o.key);if(e)return JSON.parse(e)}return null})(),t=f(),s=r||{};return t&&!(t.experimentId in s)&&(s[t.experimentId]=t),o.autopersist&&d(s),e?e in s?s[e]:null:Object.keys(s).length?s:null},w=(e=2e3,r=10)=>{document.documentElement.classList.add("wait-for-optimize");let t=0;const o=window.setInterval((()=>{(window.ga&&window.ga.loaded||t>=e)&&(document.documentElement.classList.remove("wait-for-optimize"),window.clearInterval(o)),t+=r}),r)},y=()=>{if("undefined"!=typeof window){const e={};"localStorage"in window?"sessionStorage"in window&&o.storagePreference===t.sessionStorage?e.storage=window.sessionStorage:e.storage=window.localStorage:"sessionStorage"in window&&(e.storage=window.sessionStorage),"location"in window&&"search"in window.location&&(e.location=window.location),Object.keys(e).length&&p(e)}};var m=(y(),{autopersist:n,configure:p,currentExperimentId:g,discover:y,fields:s,fromQuery:f,get:u,key:i,location:a,persist:d,preventFlicker:w,storage:c,storagePreference:l,storagePreferences:t});exports.autopersist=n,exports.configure=p,exports.currentExperimentId=g,exports.default=m,exports.discover=y,exports.fields=s,exports.fromQuery=f,exports.get=u,exports.key=i,exports.location=a,exports.persist=d,exports.preventFlicker=w,exports.storage=c,exports.storagePreference=l,exports.storagePreferences=t; | ||
// https://github.com/haensl/google-optimize-service#readme v1.1.19 Copyright 2023 HP Dietz | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("querystring");const r={localStorage:"local",sessionStorage:"session"},t={autopersist:!0,fields:["variant"],key:"optimize",location:{search:""},storage:null,storagePreference:r.localStorage},o=e=>{if(Array.isArray(e)&&e.reduce(((e,r)=>e&&"string"==typeof r),!0))t.fields=e.slice();else if(e)throw new TypeError("Invalid parameter. Expected newFields to be Array of strings.");return t.fields.slice()},s=e=>{if("boolean"==typeof e)t.autopersist=e;else if(void 0!==e)throw new TypeError("Invalid parameter. Expected shouldAutopersist to be boolean.");return t.autopersist},n=e=>{if("string"==typeof e)t.key=e;else if(e)throw new TypeError("Invalid parameter. Expected newKey to be string");return t.key},i=e=>{if(e){if(!("search"in e)||"string"!=typeof e.search)throw new TypeError('Invalid parameter. Expected newLocation to be object with string property "serach".');t.location=e}return{search:t.location.search}},a=e=>{if(e){if("object"!=typeof e)throw new TypeError("Invalid parameter. Expected storage to be object.");["getItem","setItem"].forEach((r=>{if("function"!=typeof e[r])throw new TypeError(`Invalid parameter. Expected storage to implement function ${r}.`)})),t.storage=e}return Object.assign({},t.storage)},c=e=>{if(e){if(!Object.values(r).includes(e))throw new TypeError(`Invalid parameter. Expected newStoragePreference to be on of ${Object.values(r).join(", ")}.`);t.storagePreference=e}return t.storagePreference},l=e=>{if("object"!=typeof e)throw new TypeError("Invalid parameter. Expected opts to be object.");Object.keys(t).forEach((r=>{if(r in e)try{switch(r){case"autopersist":s(e.autopersist);break;case"key":n(e.key);break;case"location":i(e.location);break;case"storage":a(e.storage);break;case"storagePreference":c(e.storagePreference);break;case"fields":o(e.fields)}}catch(e){throw new TypeError(`Invalid option: ${r}.`,e.message)}}))},p=()=>{const r={};if(t.location){const o=e.parse(t.location.search.replace(/^\?/,""));"utm_expid"in o&&(r.experimentId=o.utm_expid),"utm_referrer"in o&&(r.referrer=o.utm_referrer),(t.fields||[]).forEach((e=>{e in o&&(r[e]=o[e])}))}return Object.keys(r).length?r:null},f=(e=g())=>{t.storage&&t.storage.setItem(t.key,JSON.stringify(e))},d=()=>{if(t.location){const e=p();if(e)return e.experimentId}},g=(e=d())=>{const r=(()=>{if(t.storage){const e=t.storage.getItem(t.key);if(e)return JSON.parse(e)}return null})(),o=p(),s=r||{};return o&&!(o.experimentId in s)&&(s[o.experimentId]=o),t.autopersist&&f(s),e?e in s?s[e]:null:Object.keys(s).length?s:null},w=(e=2e3,r=10)=>{document.documentElement.classList.add("wait-for-optimize");let t=0;const o=window.setInterval((()=>{(window.ga&&window.ga.loaded||t>=e)&&(document.documentElement.classList.remove("wait-for-optimize"),window.clearInterval(o)),t+=r}),r)},u=()=>{if("undefined"!=typeof window){const e={};"localStorage"in window?"sessionStorage"in window&&t.storagePreference===r.sessionStorage?e.storage=window.sessionStorage:e.storage=window.localStorage:"sessionStorage"in window&&(e.storage=window.sessionStorage),"location"in window&&"search"in window.location&&(e.location=window.location),Object.keys(e).length&&l(e)}};var y=(u(),{autopersist:s,configure:l,currentExperimentId:d,discover:u,fields:o,fromQuery:p,get:g,key:n,location:i,persist:f,preventFlicker:w,storage:a,storagePreference:c,storagePreferences:r});exports.autopersist=s,exports.configure=l,exports.currentExperimentId=d,exports.default=y,exports.discover=u,exports.fields=o,exports.fromQuery=p,exports.get=g,exports.key=n,exports.location=i,exports.persist=f,exports.preventFlicker=w,exports.storage=a,exports.storagePreference=c,exports.storagePreferences=r; | ||
//# sourceMappingURL=google-optimize-service.cjs.js.map |
@@ -1,3 +0,3 @@ | ||
// https://github.com/haensl/google-optimize-service#readme v1.1.18 Copyright 2022 HP Dietz | ||
// https://github.com/haensl/google-optimize-service#readme v1.1.19 Copyright 2023 HP Dietz | ||
function e(e,r){return Object.prototype.hasOwnProperty.call(e,r)}var r=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function t(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}}function o(e,o,i,s){return o=o||"&",i=i||"=",null===e&&(e=void 0),"object"==typeof e?n(a(e),(function(a){var s=encodeURIComponent(t(a))+i;return r(e[a])?n(e[a],(function(e){return s+encodeURIComponent(t(e))})).join(o):s+encodeURIComponent(t(e[a]))})).join(o):s?encodeURIComponent(t(s))+i+encodeURIComponent(t(e)):""}function n(e,r){if(e.map)return e.map(r);for(var t=[],o=0;o<e.length;o++)t.push(r(e[o],o));return t}var a=Object.keys||function(e){var r=[];for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&r.push(t);return r};function i(t,o,n,a){o=o||"&",n=n||"=";var i={};if("string"!=typeof t||0===t.length)return i;var s=/\+/g;t=t.split(o);var c=1e3;a&&"number"==typeof a.maxKeys&&(c=a.maxKeys);var l=t.length;c>0&&l>c&&(l=c);for(var p=0;p<l;++p){var f,d,u,g,w=t[p].replace(s,"%20"),y=w.indexOf(n);y>=0?(f=w.substr(0,y),d=w.substr(y+1)):(f=w,d=""),u=decodeURIComponent(f),g=decodeURIComponent(d),e(i,u)?r(i[u])?i[u].push(g):i[u]=[i[u],g]:i[u]=g}return i}var s={encode:o,stringify:o,decode:i,parse:i},c={localStorage:"local",sessionStorage:"session"},l={autopersist:!0,fields:["variant"],key:"optimize",location:{search:""},storage:null,storagePreference:c.localStorage},p=e=>{if(Array.isArray(e)&&e.reduce(((e,r)=>e&&"string"==typeof r),!0))l.fields=e.slice();else if(e)throw new TypeError("Invalid parameter. Expected newFields to be Array of strings.");return l.fields.slice()},f=e=>{if("boolean"==typeof e)l.autopersist=e;else if(void 0!==e)throw new TypeError("Invalid parameter. Expected shouldAutopersist to be boolean.");return l.autopersist},d=e=>{if("string"==typeof e)l.key=e;else if(e)throw new TypeError("Invalid parameter. Expected newKey to be string");return l.key},u=e=>{if(e){if(!("search"in e)||"string"!=typeof e.search)throw new TypeError('Invalid parameter. Expected newLocation to be object with string property "serach".');l.location=e}return{search:l.location.search}},g=e=>{if(e){if("object"!=typeof e)throw new TypeError("Invalid parameter. Expected storage to be object.");["getItem","setItem"].forEach((r=>{if("function"!=typeof e[r])throw new TypeError("Invalid parameter. Expected storage to implement function ".concat(r,"."))})),l.storage=e}return Object.assign({},l.storage)},w=e=>{if(e){if(!Object.values(c).includes(e))throw new TypeError("Invalid parameter. Expected newStoragePreference to be on of ".concat(Object.values(c).join(", "),"."));l.storagePreference=e}return l.storagePreference},y=e=>{if("object"!=typeof e)throw new TypeError("Invalid parameter. Expected opts to be object.");Object.keys(l).forEach((r=>{if(r in e)try{switch(r){case"autopersist":f(e.autopersist);break;case"key":d(e.key);break;case"location":u(e.location);break;case"storage":g(e.storage);break;case"storagePreference":w(e.storagePreference);break;case"fields":p(e.fields)}}catch(e){throw new TypeError("Invalid option: ".concat(r,"."),e.message)}}))},m=()=>{var e={};if(l.location){var r=s.parse(l.location.search.replace(/^\?/,""));"utm_expid"in r&&(e.experimentId=r.utm_expid),"utm_referrer"in r&&(e.referrer=r.utm_referrer),(l.fields||[]).forEach((t=>{t in r&&(e[t]=r[t])}))}return Object.keys(e).length?e:null},v=()=>{if(l.storage){var e=l.storage.getItem(l.key);if(e)return JSON.parse(e)}return null},h=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:I();l.storage&&l.storage.setItem(l.key,JSON.stringify(e))},b=()=>{if(l.location){var e=m();if(e)return e.experimentId}},I=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:b(),r=v(),t=m(),o=r||{};return t&&!(t.experimentId in o)&&(o[t.experimentId]=t),l.autopersist&&h(o),e?e in o?o[e]:null:Object.keys(o).length?o:null},E=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2e3,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10;document.documentElement.classList.add("wait-for-optimize");var t=0,o=window.setInterval((()=>{(window.ga&&window.ga.loaded||t>=e)&&(document.documentElement.classList.remove("wait-for-optimize"),window.clearInterval(o)),t+=r}),r)},j=()=>{if("undefined"!=typeof window){var e={};"localStorage"in window?"sessionStorage"in window&&l.storagePreference===c.sessionStorage?e.storage=window.sessionStorage:e.storage=window.localStorage:"sessionStorage"in window&&(e.storage=window.sessionStorage),"location"in window&&"search"in window.location&&(e.location=window.location),Object.keys(e).length&&y(e)}},k=(j(),{autopersist:f,configure:y,currentExperimentId:b,discover:j,fields:p,fromQuery:m,get:I,key:d,location:u,persist:h,preventFlicker:E,storage:g,storagePreference:w,storagePreferences:c});export{f as autopersist,y as configure,b as currentExperimentId,k as default,j as discover,p as fields,m as fromQuery,I as get,d as key,u as location,h as persist,E as preventFlicker,g as storage,w as storagePreference,c as storagePreferences}; | ||
//# sourceMappingURL=google-optimize-service.esm.js.map |
@@ -1,2 +0,2 @@ | ||
// https://github.com/haensl/google-optimize-service#readme v1.1.18 Copyright 2022 HP Dietz | ||
// https://github.com/haensl/google-optimize-service#readme v1.1.19 Copyright 2023 HP Dietz | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["google-optimize-service"]={})}(this,(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},t(e)}function r(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var o=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function n(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}}function i(e,t,r,i){return t=t||"&",r=r||"=",null===e&&(e=void 0),"object"==typeof e?a(s(e),(function(i){var s=encodeURIComponent(n(i))+r;return o(e[i])?a(e[i],(function(e){return s+encodeURIComponent(n(e))})).join(t):s+encodeURIComponent(n(e[i]))})).join(t):i?encodeURIComponent(n(i))+r+encodeURIComponent(n(e)):""}function a(e,t){if(e.map)return e.map(t);for(var r=[],o=0;o<e.length;o++)r.push(t(e[o],o));return r}var s=Object.keys||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.push(r);return t};function c(e,t,n,i){t=t||"&",n=n||"=";var a={};if("string"!=typeof e||0===e.length)return a;var s=/\+/g;e=e.split(t);var c=1e3;i&&"number"==typeof i.maxKeys&&(c=i.maxKeys);var f=e.length;c>0&&f>c&&(f=c);for(var u=0;u<f;++u){var l,p,d,g,y=e[u].replace(s,"%20"),m=y.indexOf(n);m>=0?(l=y.substr(0,m),p=y.substr(m+1)):(l=y,p=""),d=decodeURIComponent(l),g=decodeURIComponent(p),r(a,d)?o(a[d])?a[d].push(g):a[d]=[a[d],g]:a[d]=g}return a}var f={encode:i,stringify:i,decode:c,parse:c},u={localStorage:"local",sessionStorage:"session"},l={autopersist:!0,fields:["variant"],key:"optimize",location:{search:""},storage:null,storagePreference:u.localStorage},p=function(e){if(Array.isArray(e)&&e.reduce((function(e,t){return e&&"string"==typeof t}),!0))l.fields=e.slice();else if(e)throw new TypeError("Invalid parameter. Expected newFields to be Array of strings.");return l.fields.slice()},d=function(e){if("boolean"==typeof e)l.autopersist=e;else if(void 0!==e)throw new TypeError("Invalid parameter. Expected shouldAutopersist to be boolean.");return l.autopersist},g=function(e){if("string"==typeof e)l.key=e;else if(e)throw new TypeError("Invalid parameter. Expected newKey to be string");return l.key},y=function(e){if(e){if(!("search"in e)||"string"!=typeof e.search)throw new TypeError('Invalid parameter. Expected newLocation to be object with string property "serach".');l.location=e}return{search:l.location.search}},m=function(e){if(e){if("object"!==t(e))throw new TypeError("Invalid parameter. Expected storage to be object.");["getItem","setItem"].forEach((function(t){if("function"!=typeof e[t])throw new TypeError("Invalid parameter. Expected storage to implement function ".concat(t,"."))})),l.storage=e}return Object.assign({},l.storage)},w=function(e){if(e){if(!Object.values(u).includes(e))throw new TypeError("Invalid parameter. Expected newStoragePreference to be on of ".concat(Object.values(u).join(", "),"."));l.storagePreference=e}return l.storagePreference},v=function(e){if("object"!==t(e))throw new TypeError("Invalid parameter. Expected opts to be object.");Object.keys(l).forEach((function(t){if(t in e)try{switch(t){case"autopersist":d(e.autopersist);break;case"key":g(e.key);break;case"location":y(e.location);break;case"storage":m(e.storage);break;case"storagePreference":w(e.storagePreference);break;case"fields":p(e.fields)}}catch(e){throw new TypeError("Invalid option: ".concat(t,"."),e.message)}}))},b=function(){var e={};if(l.location){var t=f.parse(l.location.search.replace(/^\?/,""));"utm_expid"in t&&(e.experimentId=t.utm_expid),"utm_referrer"in t&&(e.referrer=t.utm_referrer),(l.fields||[]).forEach((function(r){r in t&&(e[r]=t[r])}))}return Object.keys(e).length?e:null},h=function(){if(l.storage){var e=l.storage.getItem(l.key);if(e)return JSON.parse(e)}return null},I=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:j();l.storage&&l.storage.setItem(l.key,JSON.stringify(e))},E=function(){if(l.location){var e=b();if(e)return e.experimentId}},j=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:E(),t=h(),r=b(),o=t||{};return r&&!(r.experimentId in o)&&(o[r.experimentId]=r),l.autopersist&&I(o),e?e in o?o[e]:null:Object.keys(o).length?o:null},x=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2e3,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10;document.documentElement.classList.add("wait-for-optimize");var r=0,o=window.setInterval((function(){(window.ga&&window.ga.loaded||r>=e)&&(document.documentElement.classList.remove("wait-for-optimize"),window.clearInterval(o)),r+=t}),t)},k=function(){if("undefined"!=typeof window){var e={};"localStorage"in window?"sessionStorage"in window&&l.storagePreference===u.sessionStorage?e.storage=window.sessionStorage:e.storage=window.localStorage:"sessionStorage"in window&&(e.storage=window.sessionStorage),"location"in window&&"search"in window.location&&(e.location=window.location),Object.keys(e).length&&v(e)}},S=(k(),{autopersist:d,configure:v,currentExperimentId:E,discover:k,fields:p,fromQuery:b,get:j,key:g,location:y,persist:I,preventFlicker:x,storage:m,storagePreference:w,storagePreferences:u});e.autopersist=d,e.configure=v,e.currentExperimentId=E,e.default=S,e.discover=k,e.fields=p,e.fromQuery=b,e.get=j,e.key=g,e.location=y,e.persist=I,e.preventFlicker=x,e.storage=m,e.storagePreference=w,e.storagePreferences=u})); |
{ | ||
"name": "google-optimize-service", | ||
"version": "1.1.18", | ||
"version": "1.1.19", | ||
"description": "Highly customizable, dependency-free, universal, service abstraction around Google Optimize.", | ||
@@ -59,16 +59,17 @@ "main": "lib/google-optimize-service.cjs.js", | ||
"@haensl/eslint-config": "^1.4.1", | ||
"@rollup/plugin-babel": "^5.2.3", | ||
"@rollup/plugin-commonjs": "^21.0.1", | ||
"@rollup/plugin-node-resolve": "^13.0.0", | ||
"babel-jest": "^27.0.6", | ||
"@rollup/plugin-babel": "^6.0.3", | ||
"@rollup/plugin-commonjs": "^24.0.0", | ||
"@rollup/plugin-node-resolve": "^15.0.1", | ||
"@rollup/plugin-terser": "^0.3.0", | ||
"babel-jest": "^29.3.1", | ||
"eslint": "^8.5.0", | ||
"husky": "^7.0.4", | ||
"jest": "^27.0.6", | ||
"jest-junit": "^13.0.0", | ||
"husky": "^8.0.3", | ||
"jest": "^29.3.1", | ||
"jest-environment-jsdom": "^29.3.1", | ||
"jest-junit": "^15.0.0", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.38.5", | ||
"rollup": "^3.9.1", | ||
"rollup-plugin-ascii": "0.0.3", | ||
"rollup-plugin-node-polyfills": "^0.2.1", | ||
"rollup-plugin-peer-deps-external": "^2.2.4", | ||
"rollup-plugin-terser": "^7.0.2" | ||
"rollup-plugin-peer-deps-external": "^2.2.4" | ||
}, | ||
@@ -75,0 +76,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65584
19