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

google-optimize-service

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-optimize-service - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

lib/google-optimize-service.cjs.js

4

CHANGELOG.md

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

## 1.1.3
* [#22: Update dependencies.](https://github.com/haensl/google-optimize-service/issues/22)
* Refactor rollup configuration.
## 1.1.2

@@ -2,0 +6,0 @@ * [#17: Update dependencies.](https://github.com/haensl/google-optimize-service/issues/17)

414

lib/google-optimize-service.esm.js

@@ -1,412 +0,2 @@

// https://github.com/haensl/google-optimize-service#readme v1.1.2 Copyright 2020 HP Dietz
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// If obj.hasOwnProperty has been overridden, then calling
// obj.hasOwnProperty(prop) will break.
// See: https://github.com/joyent/node/issues/1707
function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
var isArray = Array.isArray || function (xs) {
return Object.prototype.toString.call(xs) === '[object Array]';
};
function stringifyPrimitive(v) {
switch (typeof v) {
case 'string':
return v;
case 'boolean':
return v ? 'true' : 'false';
case 'number':
return isFinite(v) ? v : '';
default:
return '';
}
}
function stringify (obj, sep, eq, name) {
sep = sep || '&';
eq = eq || '=';
if (obj === null) {
obj = undefined;
}
if (typeof obj === 'object') {
return map(objectKeys(obj), function(k) {
var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
if (isArray(obj[k])) {
return map(obj[k], function(v) {
return ks + encodeURIComponent(stringifyPrimitive(v));
}).join(sep);
} else {
return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
}
}).join(sep);
}
if (!name) return '';
return encodeURIComponent(stringifyPrimitive(name)) + eq +
encodeURIComponent(stringifyPrimitive(obj));
}
function map (xs, f) {
if (xs.map) return xs.map(f);
var res = [];
for (var i = 0; i < xs.length; i++) {
res.push(f(xs[i], i));
}
return res;
}
var objectKeys = Object.keys || function (obj) {
var res = [];
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
}
return res;
};
function parse(qs, sep, eq, options) {
sep = sep || '&';
eq = eq || '=';
var obj = {};
if (typeof qs !== 'string' || qs.length === 0) {
return obj;
}
var regexp = /\+/g;
qs = qs.split(sep);
var maxKeys = 1000;
if (options && typeof options.maxKeys === 'number') {
maxKeys = options.maxKeys;
}
var len = qs.length;
// maxKeys <= 0 means that we should not limit keys count
if (maxKeys > 0 && len > maxKeys) {
len = maxKeys;
}
for (var i = 0; i < len; ++i) {
var x = qs[i].replace(regexp, '%20'),
idx = x.indexOf(eq),
kstr, vstr, k, v;
if (idx >= 0) {
kstr = x.substr(0, idx);
vstr = x.substr(idx + 1);
} else {
kstr = x;
vstr = '';
}
k = decodeURIComponent(kstr);
v = decodeURIComponent(vstr);
if (!hasOwnProperty(obj, k)) {
obj[k] = v;
} else if (isArray(obj[k])) {
obj[k].push(v);
} else {
obj[k] = [obj[k], v];
}
}
return obj;
}var querystring = {
encode: stringify,
stringify: stringify,
decode: parse,
parse: parse
};
var storagePreferences = {
localStorage: 'local',
sessionStorage: 'session'
};
var config = {
autopersist: true,
fields: ['variant'],
key: 'optimize',
location: {
search: ''
},
storage: null,
storagePreference: storagePreferences.localStorage
};
var fields = newFields => {
if (Array.isArray(newFields) && newFields.reduce((isString, val) => isString && typeof val === 'string', true)) {
config.fields = newFields.slice();
} else if (newFields) {
throw new TypeError('Invalid parameter. Expected newFields to be Array of strings.');
}
return config.fields.slice();
};
var autopersist = shouldAutopersist => {
if (typeof shouldAutopersist === 'boolean') {
config.autopersist = shouldAutopersist;
} else if (typeof shouldAutopersist !== 'undefined') {
throw new TypeError('Invalid parameter. Expected shouldAutopersist to be boolean.');
}
return config.autopersist;
};
var key = newKey => {
if (typeof newKey === 'string') {
config.key = newKey;
} else if (newKey) {
throw new TypeError('Invalid parameter. Expected newKey to be string');
}
return config.key;
};
var location = newLocation => {
if (newLocation) {
if ('search' in newLocation && typeof newLocation.search === 'string') {
config.location = newLocation;
} else {
throw new TypeError('Invalid parameter. Expected newLocation to be object with string property "serach".');
}
}
return {
search: config.location.search
};
};
var storage = newStorage => {
if (newStorage) {
if (typeof newStorage !== 'object') {
throw new TypeError('Invalid parameter. Expected storage to be object.');
}
['getItem', 'setItem'].forEach(requiredFunction => {
if (typeof newStorage[requiredFunction] !== 'function') {
throw new TypeError("Invalid parameter. Expected storage to implement function ".concat(requiredFunction, "."));
}
});
config.storage = newStorage;
}
return Object.assign({}, config.storage);
};
var storagePreference = newStoragePreference => {
if (newStoragePreference) {
if (!Object.values(storagePreferences).includes(newStoragePreference)) {
throw new TypeError("Invalid parameter. Expected newStoragePreference to be on of ".concat(Object.values(storagePreferences).join(', '), "."));
}
config.storagePreference = newStoragePreference;
}
return config.storagePreference;
};
var configure = opts => {
if (typeof opts !== 'object') {
throw new TypeError('Invalid parameter. Expected opts to be object.');
}
Object.keys(config).forEach(option => {
if (option in opts) {
try {
switch (option) {
case 'autopersist':
autopersist(opts.autopersist);
break;
case 'key':
key(opts.key);
break;
case 'location':
location(opts.location);
break;
case 'storage':
storage(opts.storage);
break;
case 'storagePreference':
storagePreference(opts.storagePreference);
break;
case 'fields':
fields(opts.fields);
break;
default:
break;
}
} catch (e) {
throw new TypeError("Invalid option: ".concat(option, "."), e.message);
}
}
});
};
var fromQuery = () => {
var experiment = {};
if (config.location) {
var query = querystring.parse(config.location.search.replace(/^\?/, ''));
if ('utm_expid' in query) {
experiment.experimentId = query.utm_expid;
}
if ('utm_referrer' in query) {
experiment.referrer = query.utm_referrer;
}
(config.fields || []).forEach(field => {
if (field in query) {
experiment[field] = query[field];
}
});
}
if (Object.keys(experiment).length) {
return experiment;
}
return null;
};
var fromStorage = () => {
if (config.storage) {
var experimentsFromStorage = config.storage.getItem(config.key);
if (experimentsFromStorage) {
return JSON.parse(experimentsFromStorage);
}
}
return null;
};
var persist = function persist() {
var experiments = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : get();
if (config.storage) {
config.storage.setItem(config.key, JSON.stringify(experiments));
}
};
var currentExperimentId = () => {
if (config.location) {
var experimentInQuery = fromQuery();
if (experimentInQuery) {
return experimentInQuery.experimentId;
}
}
};
var get = function get() {
var experimentId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : currentExperimentId();
var experimentsFromStorage = fromStorage();
var experimentInQuery = fromQuery();
var experiments = experimentsFromStorage || {};
if (experimentInQuery && !(experimentInQuery.experimentId in experiments)) {
experiments[experimentInQuery.experimentId] = experimentInQuery;
}
if (config.autopersist) {
persist(experiments);
}
if (experimentId) {
if (experimentId in experiments) {
return experiments[experimentId];
}
return null;
}
if (Object.keys(experiments).length) {
return experiments;
}
return null;
};
var preventFlicker = function preventFlicker() {
var timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2000;
var intervalMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
document.documentElement.classList.add('wait-for-optimize');
var dt = 0;
var interval = window.setInterval(() => {
if (window.ga && window.ga.loaded || dt >= timeout) {
document.documentElement.classList.remove('wait-for-optimize');
window.clearInterval(interval);
}
dt += intervalMs;
}, intervalMs);
};
var discover = () => {
if (typeof window !== 'undefined') {
var opts = {};
if ('localStorage' in window) {
if ('sessionStorage' in window && config.storagePreference === storagePreferences.sessionStorage) {
opts.storage = window.sessionStorage;
} else {
opts.storage = window.localStorage;
}
} else if ('sessionStorage' in window) {
opts.storage = window.sessionStorage;
}
if ('location' in window && 'search' in window.location) {
opts.location = window.location;
}
if (Object.keys(opts).length) {
configure(opts);
}
}
};
var googleOptimizeService = (() => {
discover();
return {
autopersist,
configure,
currentExperimentId,
discover,
fields,
fromQuery,
get,
key,
location,
persist,
preventFlicker,
storage,
storagePreference,
storagePreferences
};
})();
export default googleOptimizeService;
export { autopersist, configure, currentExperimentId, discover, fields, fromQuery, get, key, location, persist, preventFlicker, storage, storagePreference, storagePreferences };
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)}},x=(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 default x;export{f as autopersist,y as configure,b as currentExperimentId,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
{
"name": "google-optimize-service",
"version": "1.1.2",
"version": "1.1.3",
"description": "Highly customizable, dependency-free, universal, service abstraction around Google Optimize.",
"main": "lib/google-optimize-service.node.js",
"main": "lib/google-optimize-service.cjs.js",
"module": "lib/google-optimize-service.esm.js",
"unpkg": "lib/google-optimize-service.min.js",
"jsdelivr": "lib/google-optimize-service.min.js",
"unpkg": "lib/google-optimize-service.umd.js",
"jsdelivr": "lib/google-optimize-service.umd.js",
"scripts": {

@@ -54,17 +54,23 @@ "build": "rollup -c",

"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"@babel/core": "^7.11.6",
"@babel/plugin-transform-runtime": "^7.11.5",
"@babel/preset-env": "^7.11.5",
"@haensl/eslint-config": "^1.3.0",
"babel-jest": "^25.3.0",
"eslint": "^6.8.0",
"husky": "^4.2.5",
"jest": "^25.3.0",
"jest-junit": "^10.0.0",
"rollup": "^2.6.1",
"@rollup/plugin-babel": "^5.2.1",
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"babel-jest": "^26.3.0",
"eslint": "^7.8.1",
"husky": "^4.3.0",
"jest": "^26.4.2",
"jest-junit": "^11.1.0",
"rollup": "^2.26.11",
"rollup-plugin-ascii": "0.0.3",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^5.3.0"
"rollup-plugin-node-polyfills": "^0.2.1",
"rollup-plugin-peer-deps-external": "^2.2.3",
"rollup-plugin-terser": "^7.0.2"
},
"dependencies": {
"@babel/runtime": "^7.11.2"
}
}
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