@financial-times/ads-config
Advanced tools
Comparing version 1.3.0-beta.3 to 1.3.0-beta.4
@@ -54,11 +54,2 @@ function _typeof(obj) { | ||
/** | ||
* Test if an object is a String | ||
* @param {object} obj The object to be tested | ||
* @returns {boolean} true if the object is of type String, otherwise false | ||
*/ | ||
var isString = function isString(obj) { | ||
return is(obj) === 'String'; | ||
}; | ||
/** | ||
* Test if an object is a Function | ||
@@ -73,11 +64,2 @@ * @param {object} obj The object to be tested | ||
/** | ||
* Test if an object is a Storage object | ||
* @param {object} obj The object to be tested | ||
* @returns {boolean} true if the object is of type Storage, otherwise false | ||
*/ | ||
var isStorage = function isStorage(obj) { | ||
return is(obj) === 'Storage'; | ||
}; | ||
/** | ||
* Test if an object is an Object | ||
@@ -109,6 +91,5 @@ * @param {object} obj The object to be tested | ||
var isPlainObject = function isPlainObject(obj) { | ||
var hop = Object.prototype.hasOwnProperty; // Must be an Object. | ||
// Must be an Object. | ||
// Because of IE, we also have to check the presence of the constructor property. | ||
// Make sure that DOM nodes and window objects don't pass through, as well | ||
if (!obj || !isObject(obj) || obj.nodeType || isWindow(obj)) { | ||
@@ -138,14 +119,2 @@ return false; | ||
}; | ||
/** | ||
* Test if an object is a string with a length | ||
* @param {object} str The object to be tested | ||
* @returns {boolean} true if the object is a string with a length greater than 0 | ||
*/ | ||
var isNonEmptyString = function isNonEmptyString(str) { | ||
return isString(str) && Boolean(str.length); | ||
}; | ||
var isElement = function isElement(element) { | ||
return element && element.nodeType === 1 && element.tagName || false; | ||
}; | ||
function extend() { | ||
@@ -224,262 +193,9 @@ /* jshint forin: false */ | ||
} | ||
/** | ||
* Create an object hash from a delimited string | ||
* Beware all properties on the resulting object will have string values. | ||
* @param {string} str The string to transform | ||
* @param {string|regexp} delimiter The character that delimits each name/value pair | ||
* @param {string} pairing The character that separates the name from the value | ||
* @return {object} | ||
* | ||
*/ | ||
var hash = function hash(str, delimiter, pairing) { | ||
var pair; | ||
var value; | ||
var hashObj = {}; | ||
if (str && str.split) { | ||
str = str.split(delimiter); | ||
for (var idx = 0, l = str.length; idx < l; idx += 1) { | ||
value = str[idx]; | ||
pair = value.split(pairing); | ||
if (pair.length > 1) { | ||
hashObj[pair[0].trim()] = pair.slice(1).join(pairing); | ||
} | ||
} | ||
} | ||
return hashObj; | ||
}; | ||
/** | ||
* Takes a script URL as a string value, creates a new script element, sets the src and attaches to the page | ||
* The async value of the script can be set by the seccond parameter, which is a boolean | ||
* Note, we should use protocol-relative URL paths to ensure we don't run into http/https issues | ||
* @param {string} scriptUrl The url to the script file to be added | ||
* @param {boolean} async Set the async attribute on the script tag | ||
* @param {function} callback A function to run when the script loads | ||
* @param {function} errorcb A function to run if the script fails to load | ||
* @returns {HTMLElement} the created script tag | ||
*/ | ||
var attach = function attach(scriptUrl, async, callback, errorcb, autoRemove) { | ||
var tag = document.createElement('script'); | ||
var node = document.getElementsByTagName('script')[0]; | ||
var hasRun = false; | ||
function processCallback(callback) { | ||
/* istanbul ignore else */ | ||
if (!hasRun) { | ||
callback.call(); | ||
hasRun = true; | ||
/* istanbul ignore else */ | ||
if (autoRemove) { | ||
tag.parentElement.removeChild(tag); | ||
} | ||
} | ||
} | ||
tag.setAttribute('src', scriptUrl); | ||
tag.setAttribute('o-ads', ''); | ||
/* istanbul ignore else */ | ||
if (async) { | ||
tag.async = 'true'; | ||
} | ||
/* istanbul ignore else */ | ||
if (isFunction(callback)) { | ||
/* istanbul ignore if - legacy IE code, won't test */ | ||
if (hop.call(tag, 'onreadystatechange')) { | ||
tag.onreadystatechange = function () { | ||
if (tag.readyState === 'loaded') { | ||
processCallback(callback); | ||
} | ||
}; | ||
} else { | ||
tag.onload = function () { | ||
processCallback(callback); | ||
}; | ||
} | ||
} | ||
/* istanbul ignore else */ | ||
if (isFunction(errorcb)) { | ||
tag.onerror = function () { | ||
processCallback(errorcb); | ||
}; | ||
} // Use insert before, append child has issues with script tags in some browsers. | ||
node.parentNode.insertBefore(tag, node); | ||
return tag; | ||
}; | ||
/** | ||
* return the current documents referrer or an empty string if non exists | ||
* This method enables us to mock the referrer in our tests reliably and doesn't really serve any other purpose | ||
* @returns {string} document.referrer | ||
*/ | ||
/* istanbul ignore next - cannot reliably test value of referer */ | ||
var getReferrer = function getReferrer() { | ||
return document.referrer || ''; | ||
}; | ||
/** | ||
* Remove hyphens from a string and upper case the following letter | ||
* @param {string} string the string to parse | ||
* @returns {string} | ||
*/ | ||
var dehyphenise = function dehyphenise(string) { | ||
return string.replace(/(-)([a-z])/g, function (match, hyphen, letter) { | ||
return letter.toUpperCase(); | ||
}); | ||
}; | ||
/** | ||
* remove prefixes from o-ads data attributes and dehyphenise the name | ||
* @param {string|} name the name of the attribute to parse | ||
* @returns {string} | ||
*/ | ||
var parseAttributeName = function parseAttributeName(attribute) { | ||
var name = isString(attribute) ? attribute : attribute.name; | ||
return dehyphenise(name.replace(/(data-)?o-ads-/, '')); | ||
}; | ||
/** | ||
* return the current documents url or an empty string if non exists | ||
* This method enables us to mock the document location string in our tests reliably and doesn't really serve any other purpose | ||
* @returns {string} | ||
*/ | ||
/* istanbul ignore next - cannot reliably test value of location */ | ||
var getLocation = function getLocation() { | ||
return document.location.href || ''; | ||
}; | ||
/** | ||
* return the current documents search or an empty string if non exists | ||
* also strips the initial ? from the search string for easier parsing | ||
* This method enables us to mock the search string in our tests reliably and doesn't really serve any other purpose | ||
* @returns {string} | ||
*/ | ||
var getQueryString = function getQueryString() { | ||
return document.location.search.substring(1) || ''; | ||
}; | ||
/** | ||
* Get a query string parameter by name from a url | ||
* @param name | ||
* @param url | ||
* @returns {string | null} | ||
*/ | ||
var getQueryParamByName = function getQueryParamByName(name, url) { | ||
url = url || window.location.href; | ||
name = name.replace(/[[\]]/g, '\\$&'); | ||
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'); | ||
var results = regex.exec(url); | ||
if (!results) { | ||
return null; | ||
} | ||
if (!results[2]) { | ||
return ''; | ||
} | ||
return decodeURIComponent(results[2].replace(/\+/g, ' ')); | ||
}; | ||
/** | ||
* returns a timestamp of the current date/time in the format YYYYMMDDHHMMSS | ||
* @returns {string} | ||
*/ | ||
var getTimestamp = function getTimestamp() { | ||
var now = new Date(); | ||
return [now.getFullYear(), "0".concat(now.getMonth() + 1).slice(-2), "0".concat(now.getDate()).slice(-2), "0".concat(now.getHours()).slice(-2), "0".concat(now.getMinutes()).slice(-2), "0".concat(now.getSeconds()).slice(-2)].join(''); | ||
}; | ||
/** | ||
* Given the window object of an iframe this method returns the o-ads slot name | ||
* that rendered the iframe, if the iframe was not rendered by o-ads this will | ||
* return false | ||
* @param {window} a window object | ||
* @returns {String|Boolean} | ||
*/ | ||
var iframeToSlotName = function iframeToSlotName(iframeWindow) { | ||
// capture all iframes in the page in a live node list | ||
var iframes = document.getElementsByTagName('iframe'); | ||
var slotName; | ||
var node; | ||
var i = iframes.length; // Figure out which iframe DOM node we have the window for | ||
while (i--) { | ||
/* istanbul ignore else */ | ||
if (iframes[i].contentWindow === iframeWindow) { | ||
node = iframes[i]; | ||
break; | ||
} | ||
} | ||
/* istanbul ignore else */ | ||
if (node) { | ||
// find the closest parent with a data-o-ads-name attribute, that's our slot name | ||
while (node.parentNode) { | ||
slotName = node.getAttribute('data-o-ads-name'); | ||
/* istanbul ignore else */ | ||
if (slotName) { | ||
return slotName; | ||
} | ||
node = node.parentNode; | ||
} | ||
} | ||
return false; | ||
}; | ||
var buildObjectFromArray = function buildObjectFromArray(targetObject) { | ||
return targetObject.reduce(function (prev, data) { | ||
prev[data.key] = data.value; | ||
return prev; | ||
}, {}); | ||
}; | ||
var cookie = function cookie(name) { | ||
var val = document.cookie.match("(^|;)\\s*".concat(name, "\\s*=\\s*([^;]+)")); | ||
return val ? val.pop() : null; | ||
}; | ||
var metricsSampleThreshold = Math.random(); | ||
function inSample(sampleSize) { | ||
return typeof sampleSize === 'undefined' || sampleSize > metricsSampleThreshold; | ||
} | ||
var utils = { | ||
isArray: isArray, | ||
isString: isString, | ||
isFunction: isFunction, | ||
isStorage: isStorage, | ||
isObject: isObject, | ||
isWindow: isWindow, | ||
isPlainObject: isPlainObject, | ||
isNonEmptyString: isNonEmptyString, | ||
isElement: isElement, | ||
extend: extend, | ||
hash: hash, | ||
attach: attach, | ||
getReferrer: getReferrer, | ||
dehyphenise: dehyphenise, | ||
parseAttributeName: parseAttributeName, | ||
getLocation: getLocation, | ||
getQueryString: getQueryString, | ||
getQueryParamByName: getQueryParamByName, | ||
getTimestamp: getTimestamp, | ||
iframeToSlotName: iframeToSlotName, | ||
buildObjectFromArray: buildObjectFromArray, | ||
cookie: cookie, | ||
inSample: inSample | ||
extend: extend | ||
}; | ||
@@ -626,1 +342,2 @@ | ||
export { clear, init }; | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzIjpbIi4uL3NyYy91dGlscy9pbmRleC5qcyIsIi4uL3NyYy9pbmRleC5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyIvKipcbiAqIFV0aWxpdHkgbWV0aG9kcyBmb3IgdGhlIGFkdmVydGlzaW5nIGxpYnJhcnkuXG4gKiBAYXV0aG9yIE9yaWdhbWkgQWR2ZXJ0aXNpbmcsIG9yaWdhbWkuYWR2ZXJ0aXNpbmdAZnQuY29tXG4gKiBAbW9kdWxlIHV0aWxzXG4gKi9cbmNvbnN0IGhvcCA9IE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHk7XG5cbi8qKlxuICogVXNlcyBvYmplY3QgcHJvdG90eXBlIHRvU3RyaW5nIG1ldGhvZCB0byBnZXQgYXQgdGhlIHR5cGUgb2Ygb2JqZWN0IHdlIGFyZSBkZWFsaW5nLFxuICogSUUgcmV0dXJucyBbb2JqZWN0IE9iamVjdF0gZm9yIG51bGwgYW5kIHVuZGVmaW5lZCBzbyB3ZSBuZWVkIHRvIGZpbHRlciB0aG9zZVxuICogaHR0cDovL2VzNS5naXRodWIuY29tLyN4MTUuMi40LjJcbiAqIEBwc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CxNQUFNLENBQUMxRSxTQUFQLENBQWlCaUYsSUFBakIsR0FBd0IsWUFBVztBQUNsQyxPQUFLTixLQUFMLEdBQWFULEtBQUssQ0FBQzlDLE1BQU4sQ0FBYSxJQUFiLEVBQW1CLEVBQW5CLEVBQXVCWSxRQUF2QixFQUFpQ3FDLGlCQUFpQixFQUFsRCxFQUFzRGIsc0JBQXNCLEVBQTVFLENBQWI7QUFDQSxTQUFPLEtBQUttQixLQUFaO0FBQ0EsQ0FIRDs7QUFLQSxJQUFNTyxNQUFNLEdBQUcsSUFBSVIsTUFBSixFQUFmO0FBQ0EsWUFBZVEsTUFBTSxDQUFDTixNQUFQLENBQWNPLElBQWQsQ0FBbUJELE1BQW5CLENBQWY7SUFDYUQsSUFBSSxHQUFHQyxNQUFNLENBQUNELElBQVAsQ0FBWUUsSUFBWixDQUFpQkQsTUFBakI7SUFDUEYsS0FBSyxHQUFHRSxNQUFNLENBQUNGLEtBQVAsQ0FBYUcsSUFBYixDQUFrQkQsTUFBbEI7Ozs7OyJ9 |
{ | ||
"name": "@financial-times/ads-config", | ||
"version": "1.3.0-beta.3", | ||
"version": "1.3.0-beta.4", | ||
"description": "A library for holding the configuration properties for an FT.ads.gpt instance", | ||
@@ -9,3 +9,4 @@ "main": "dist/index.js", | ||
"dev": "NODE_ENV=development rollup -c rollup.config.dev.js --watch", | ||
"build": "npm run clean && rollup -c" | ||
"build": "npm run clean && rollup -c", | ||
"test": "karma start karma.conf.js --single-run" | ||
}, | ||
@@ -20,2 +21,7 @@ "keywords": [], | ||
"@rollup/plugin-node-resolve": "^11.0.1", | ||
"karma": "^5.2.3", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-qunit": "^4.1.1", | ||
"karma-rollup": "^1.0.1", | ||
"qunit": "^2.13.0", | ||
"rollup": "^2.36.1", | ||
@@ -22,0 +28,0 @@ "rollup-plugin-babel": "^4.4.0", |
@@ -1,9 +0,9 @@ | ||
import babel from 'rollup-plugin-babel' | ||
import commonjs from '@rollup/plugin-commonjs' | ||
import nodeResolve from '@rollup/plugin-node-resolve' | ||
import pkg from './package.json' | ||
const babel = require('rollup-plugin-babel'); | ||
const commonjs = require('@rollup/plugin-commonjs'); | ||
const nodeResolve = require('@rollup/plugin-node-resolve').default; | ||
const pkg = require('./package.json'); | ||
//const external = [...Object.keys(pkg.dependencies), ...Object.keys(pkg.peerDependencies)] | ||
export default [ | ||
module.exports = [ | ||
{ | ||
@@ -15,3 +15,4 @@ input: 'src/index.js', | ||
file: pkg.main, | ||
format: 'es' | ||
format: 'es', | ||
sourcemap: 'inline' | ||
}, | ||
@@ -18,0 +19,0 @@ plugins: [ |
@@ -38,11 +38,2 @@ /** | ||
/** | ||
* Test if an object is a String | ||
* @param {object} obj The object to be tested | ||
* @returns {boolean} true if the object is of type String, otherwise false | ||
*/ | ||
export const isString = function (obj) { | ||
return is(obj) === 'String'; | ||
}; | ||
/** | ||
* Test if an object is a Function | ||
@@ -57,11 +48,2 @@ * @param {object} obj The object to be tested | ||
/** | ||
* Test if an object is a Storage object | ||
* @param {object} obj The object to be tested | ||
* @returns {boolean} true if the object is of type Storage, otherwise false | ||
*/ | ||
export const isStorage = function (obj) { | ||
return is(obj) === 'Storage'; | ||
}; | ||
/** | ||
* Test if an object is an Object | ||
@@ -92,4 +74,2 @@ * @param {object} obj The object to be tested | ||
export const isPlainObject = function (obj) { | ||
const hop = Object.prototype.hasOwnProperty; | ||
// Must be an Object. | ||
@@ -123,15 +103,2 @@ // Because of IE, we also have to check the presence of the constructor property. | ||
/** | ||
* Test if an object is a string with a length | ||
* @param {object} str The object to be tested | ||
* @returns {boolean} true if the object is a string with a length greater than 0 | ||
*/ | ||
export const isNonEmptyString = function (str) { | ||
return isString(str) && Boolean(str.length); | ||
}; | ||
export const isElement = function (element) { | ||
return element && element.nodeType === 1 && element.tagName || false; | ||
}; | ||
export function extend() { | ||
@@ -212,258 +179,9 @@ /* jshint forin: false */ | ||
/** | ||
* Create an object hash from a delimited string | ||
* Beware all properties on the resulting object will have string values. | ||
* @param {string} str The string to transform | ||
* @param {string|regexp} delimiter The character that delimits each name/value pair | ||
* @param {string} pairing The character that separates the name from the value | ||
* @return {object} | ||
* | ||
*/ | ||
export const hash = function (str, delimiter, pairing) { | ||
let pair; | ||
let value; | ||
const hashObj = {}; | ||
if (str && str.split) { | ||
str = str.split(delimiter); | ||
for (let idx = 0, l = str.length; idx < l; idx += 1) { | ||
value = str[idx]; | ||
pair = value.split(pairing); | ||
if (pair.length > 1) { | ||
hashObj[pair[0].trim()] = pair.slice(1).join(pairing); | ||
} | ||
} | ||
} | ||
return hashObj; | ||
}; | ||
/** | ||
* Takes a script URL as a string value, creates a new script element, sets the src and attaches to the page | ||
* The async value of the script can be set by the seccond parameter, which is a boolean | ||
* Note, we should use protocol-relative URL paths to ensure we don't run into http/https issues | ||
* @param {string} scriptUrl The url to the script file to be added | ||
* @param {boolean} async Set the async attribute on the script tag | ||
* @param {function} callback A function to run when the script loads | ||
* @param {function} errorcb A function to run if the script fails to load | ||
* @returns {HTMLElement} the created script tag | ||
*/ | ||
export const attach = function (scriptUrl, async, callback, errorcb, autoRemove) { | ||
const tag = document.createElement('script'); | ||
const node = document.getElementsByTagName('script')[0]; | ||
let hasRun = false; | ||
function processCallback(callback) { | ||
/* istanbul ignore else */ | ||
if (!hasRun) { | ||
callback.call(); | ||
hasRun = true; | ||
/* istanbul ignore else */ | ||
if (autoRemove) { | ||
tag.parentElement.removeChild(tag); | ||
} | ||
} | ||
} | ||
tag.setAttribute('src', scriptUrl); | ||
tag.setAttribute('o-ads', ''); | ||
/* istanbul ignore else */ | ||
if (async) { | ||
tag.async = 'true'; | ||
} | ||
/* istanbul ignore else */ | ||
if (isFunction(callback)) { | ||
/* istanbul ignore if - legacy IE code, won't test */ | ||
if (hop.call(tag, 'onreadystatechange')) { | ||
tag.onreadystatechange = function () { | ||
if (tag.readyState === 'loaded') { | ||
processCallback(callback); | ||
} | ||
}; | ||
} else { | ||
tag.onload = function () { | ||
processCallback(callback); | ||
}; | ||
} | ||
} | ||
/* istanbul ignore else */ | ||
if (isFunction(errorcb)) { | ||
tag.onerror = function () { | ||
processCallback(errorcb); | ||
}; | ||
} | ||
// Use insert before, append child has issues with script tags in some browsers. | ||
node.parentNode.insertBefore(tag, node); | ||
return tag; | ||
}; | ||
/** | ||
* return the current documents referrer or an empty string if non exists | ||
* This method enables us to mock the referrer in our tests reliably and doesn't really serve any other purpose | ||
* @returns {string} document.referrer | ||
*/ | ||
/* istanbul ignore next - cannot reliably test value of referer */ | ||
export const getReferrer = function () { | ||
return document.referrer || ''; | ||
}; | ||
/** | ||
* Remove hyphens from a string and upper case the following letter | ||
* @param {string} string the string to parse | ||
* @returns {string} | ||
*/ | ||
export const dehyphenise = function (string) { | ||
return string.replace(/(-)([a-z])/g, function (match, hyphen, letter) { | ||
return letter.toUpperCase(); | ||
}); | ||
}; | ||
/** | ||
* remove prefixes from o-ads data attributes and dehyphenise the name | ||
* @param {string|} name the name of the attribute to parse | ||
* @returns {string} | ||
*/ | ||
export const parseAttributeName = function (attribute) { | ||
const name = isString(attribute) ? attribute : attribute.name; | ||
return dehyphenise(name.replace(/(data-)?o-ads-/, '')); | ||
}; | ||
/** | ||
* return the current documents url or an empty string if non exists | ||
* This method enables us to mock the document location string in our tests reliably and doesn't really serve any other purpose | ||
* @returns {string} | ||
*/ | ||
/* istanbul ignore next - cannot reliably test value of location */ | ||
export const getLocation = function () { | ||
return document.location.href || ''; | ||
}; | ||
/** | ||
* return the current documents search or an empty string if non exists | ||
* also strips the initial ? from the search string for easier parsing | ||
* This method enables us to mock the search string in our tests reliably and doesn't really serve any other purpose | ||
* @returns {string} | ||
*/ | ||
export const getQueryString = function () { | ||
return document.location.search.substring(1) || ''; | ||
}; | ||
/** | ||
* Get a query string parameter by name from a url | ||
* @param name | ||
* @param url | ||
* @returns {string | null} | ||
*/ | ||
export const getQueryParamByName = function (name, url) { | ||
url = url || window.location.href; | ||
name = name.replace(/[[\]]/g, '\\$&'); | ||
const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'); | ||
const results = regex.exec(url); | ||
if (!results) { | ||
return null; | ||
} | ||
if (!results[2]) { | ||
return ''; | ||
} | ||
return decodeURIComponent(results[2].replace(/\+/g, ' ')); | ||
}; | ||
/** | ||
* returns a timestamp of the current date/time in the format YYYYMMDDHHMMSS | ||
* @returns {string} | ||
*/ | ||
export const getTimestamp = function () { | ||
const now = new Date(); | ||
return [ | ||
now.getFullYear(), | ||
`0${now.getMonth() + 1}`.slice(-2), | ||
`0${now.getDate()}`.slice(-2), | ||
`0${now.getHours()}`.slice(-2), | ||
`0${now.getMinutes()}`.slice(-2), | ||
`0${now.getSeconds()}`.slice(-2), | ||
].join(''); | ||
}; | ||
/** | ||
* Given the window object of an iframe this method returns the o-ads slot name | ||
* that rendered the iframe, if the iframe was not rendered by o-ads this will | ||
* return false | ||
* @param {window} a window object | ||
* @returns {String|Boolean} | ||
*/ | ||
export const iframeToSlotName = function (iframeWindow) { | ||
// capture all iframes in the page in a live node list | ||
const iframes = document.getElementsByTagName('iframe'); | ||
let slotName; | ||
let node; | ||
let i = iframes.length; | ||
// Figure out which iframe DOM node we have the window for | ||
while (i--) { | ||
/* istanbul ignore else */ | ||
if (iframes[i].contentWindow === iframeWindow) { | ||
node = iframes[i]; | ||
break; | ||
} | ||
} | ||
/* istanbul ignore else */ | ||
if (node) { | ||
// find the closest parent with a data-o-ads-name attribute, that's our slot name | ||
while (node.parentNode) { | ||
slotName = node.getAttribute('data-o-ads-name'); | ||
/* istanbul ignore else */ | ||
if (slotName) { | ||
return slotName; | ||
} | ||
node = node.parentNode; | ||
} | ||
} | ||
return false; | ||
}; | ||
export const buildObjectFromArray = function buildObjectFromArray(targetObject) { | ||
return targetObject.reduce((prev, data) => { | ||
prev[data.key] = data.value; | ||
return prev; | ||
}, {}); | ||
}; | ||
export const cookie = function (name) { | ||
const val = document.cookie.match(`(^|;)\\s*${name}\\s*=\\s*([^;]+)`); | ||
return val ? val.pop() : null; | ||
}; | ||
const metricsSampleThreshold = Math.random(); | ||
export function inSample(sampleSize) { | ||
return typeof sampleSize === 'undefined' || sampleSize > metricsSampleThreshold; | ||
} | ||
export default { | ||
isArray, | ||
isString, | ||
isFunction, | ||
isStorage, | ||
isObject, | ||
isWindow, | ||
isPlainObject, | ||
isNonEmptyString, | ||
isElement, | ||
extend, | ||
hash, | ||
attach, | ||
getReferrer, | ||
dehyphenise, | ||
parseAttributeName, | ||
getLocation, | ||
getQueryString, | ||
getQueryParamByName, | ||
getTimestamp, | ||
iframeToSlotName, | ||
buildObjectFromArray, | ||
cookie, | ||
inSample, | ||
}; |
@@ -1,10 +0,17 @@ | ||
/* globals QUnit: false, $: false */ | ||
/* globals QUnit: false */ | ||
'use strict'; //eslint-disable-line | ||
QUnit.module('config'); | ||
import { fixturesContainer } from '../qunit/helpers' | ||
import utils from '../../src/utils' | ||
import config, { init, clear } from '../../src' | ||
QUnit.module('config') | ||
config.init = init | ||
config.clear = clear | ||
QUnit.test('Config get/set', function(assert) { | ||
this.ads.config.init(); | ||
this.ads.config.clear(); | ||
config.init(); | ||
config.clear(); | ||
let result; | ||
@@ -17,8 +24,8 @@ const key = 'key'; | ||
assert.ok($.isFunction(this.ads.config), 'The set method exists'); | ||
assert.ok(utils.isFunction(config), 'The set method exists'); | ||
result = this.ads.config(key, value); | ||
result = config(key, value); | ||
assert.deepEqual(result, value, 'passing a key+value returns the value.'); | ||
result = this.ads.config(); | ||
result = config(); | ||
const obj = {}; | ||
@@ -28,21 +35,21 @@ obj[key] = value; | ||
result = this.ads.config(key); | ||
result = config(key); | ||
assert.deepEqual(result, value, 'passing a valid key returns the value.'); | ||
result = this.ads.config(invalid); | ||
result = config(invalid); | ||
assert.deepEqual(result, undefined, 'passing an invalid key returns undefined.'); | ||
result = this.ads.config(key, value2); | ||
result = config(key, value2); | ||
assert.deepEqual(result, value2, 'set an existing key returns the new value.'); | ||
result = this.ads.config(key); | ||
result = config(key); | ||
assert.deepEqual(result, value2, 'get returns the new value.'); | ||
this.ads.config(key, value2); | ||
this.ads.config(key2, value2); | ||
result = this.ads.config(); | ||
config(key, value2); | ||
config(key2, value2); | ||
result = config(); | ||
assert.ok(result[key], 'configuration has got first key set'); | ||
assert.ok(result[key2], 'configuration has got second key set'); | ||
this.ads.config.clear(key); | ||
result = this.ads.config(); | ||
config.clear(key); | ||
result = config(); | ||
assert.notOk(result[key], 'first key has been removed'); | ||
@@ -53,4 +60,4 @@ assert.ok(result[key2], 'second key is still set'); | ||
QUnit.test('Config get/set - mulitple', function(assert) { | ||
this.ads.config.init(true); | ||
this.ads.config.clear(); | ||
config.init(true); | ||
config.clear(); | ||
const obj = { | ||
@@ -62,6 +69,6 @@ 'some': 'config', | ||
let result = this.ads.config(obj); | ||
let result = config(obj); | ||
assert.deepEqual(result, obj, 'set multiple key/values using an object.'); | ||
result = this.ads.config(); | ||
result = config(); | ||
assert.deepEqual(result, obj, 'get returns the new values.'); | ||
@@ -71,3 +78,3 @@ }); | ||
QUnit.test('Config defaults', function(assert) { | ||
this.ads.init(); | ||
init(); | ||
const flags = { | ||
@@ -77,5 +84,5 @@ refresh: true, | ||
}; | ||
const result = this.ads.config(); | ||
const result = config(); | ||
assert.ok(result.hasOwnProperty('flags'), 'default properties have been added to config'); | ||
assert.deepEqual(this.ads.config('flags'), flags, 'Config returns the correct value'); | ||
assert.deepEqual(config('flags'), flags, 'Config returns the correct value'); | ||
}); | ||
@@ -85,5 +92,5 @@ | ||
const save = window.JSON; | ||
this.fixturesContainer.get().insertAdjacentHTML('beforeend', '<script data-o-ads-config type="application/json">{"dfpsite" : "site.site","dfpzone" : "zone.zone"}</script>'); | ||
this.ads.init(); | ||
let result = this.ads.config(); | ||
fixturesContainer.get().insertAdjacentHTML('beforeend', '<script data-o-ads-config type="application/json">{"dfpsite" : "site.site","dfpzone" : "zone.zone"}</script>'); | ||
init(); | ||
let result = config(); | ||
assert.ok(result.dfpzone, 'Config has been fetched from the inline declarative script'); | ||
@@ -93,4 +100,4 @@ | ||
window['JSON'] = undefined; | ||
this.ads.init(); | ||
result = this.ads.config(); | ||
init(); | ||
result = config(); | ||
assert.notOk(result.dfpsite, 'no DFP Site - when JSON not available the declarative config is not parsed'); | ||
@@ -102,6 +109,6 @@ assert.notOk(result.dfpzone, 'no DFP zone - when JSON not available the declarative config is not parsed'); | ||
QUnit.test('Config fetchDeclaritive, multiple script tags', function(assert) { | ||
this.fixturesContainer.get().insertAdjacentHTML('beforeend', '<script data-o-ads-config type="application/json">{"athing" : "thing", "anotherthing" : "another"}</script>'); | ||
this.fixturesContainer.get().insertAdjacentHTML('beforeend', '<script data-o-ads-config type="application/json">{"more" : "evenmore"}</script>'); | ||
this.ads.init(); | ||
const result = this.ads.config(); | ||
fixturesContainer.get().insertAdjacentHTML('beforeend', '<script data-o-ads-config type="application/json">{"athing" : "thing", "anotherthing" : "another"}</script>'); | ||
fixturesContainer.get().insertAdjacentHTML('beforeend', '<script data-o-ads-config type="application/json">{"more" : "evenmore"}</script>'); | ||
init(); | ||
const result = config(); | ||
assert.equal(result.athing, 'thing', 'data-o-ads-size attribute'); | ||
@@ -112,4 +119,4 @@ assert.equal(result.more, 'evenmore', 'data-o-ads-size attribute'); | ||
QUnit.test('Config deep extends so default options like formats aren\'t overwritten', function(assert) { | ||
this.ads.init(); | ||
const result = this.ads.config({formats: { someNewFormat: { sizes: [[2, 2]]}}}); | ||
init(); | ||
const result = config({formats: { someNewFormat: { sizes: [[2, 2]]}}}); | ||
assert.ok(result.formats.HalfPage, 'predefined formats still exist'); | ||
@@ -122,3 +129,3 @@ assert.ok(result.formats.someNewFormat, 'new format is added'); | ||
Array.prototype.customTestFunction = function () {}; // eslint-disable-line no-extend-native | ||
this.ads.init(); | ||
init(); | ||
const flags = { | ||
@@ -134,6 +141,6 @@ refresh: true, | ||
}; | ||
const result = this.ads.config(); | ||
const result = config(); | ||
assert.ok(result.hasOwnProperty('flags'), 'default properties have been added to config'); | ||
assert.deepEqual(this.ads.config('flags'), flags, 'Config returns the correct value'); | ||
assert.deepEqual(this.ads.config('responsive'), repsonsiveDefaults, 'Config returns the correct values for responsive slots'); | ||
assert.deepEqual(config('flags'), flags, 'Config returns the correct value'); | ||
assert.deepEqual(config('responsive'), repsonsiveDefaults, 'Config returns the correct values for responsive slots'); | ||
@@ -140,0 +147,0 @@ delete Array.prototype.customTestFunction; |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances 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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
48395
11
0
12
889
3