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

@financial-times/o-ads

Package Overview
Dependencies
Maintainers
14
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@financial-times/o-ads - npm Package Compare versions

Comparing version 10.5.0 to 11.0.0

61

browser.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _config = _interopRequireWildcard(require("./dist/js/config"));
var _slots = _interopRequireDefault(require("./dist/js/slots"));
var _gpt = _interopRequireDefault(require("./dist/js/ad-servers/gpt"));
var _krux = _interopRequireDefault(require("./dist/js/data-providers/krux"));
var _api = _interopRequireDefault(require("./dist/js/data-providers/api"));
var _moat = _interopRequireDefault(require("./dist/js/data-providers/moat"));
var _targeting = _interopRequireDefault(require("./dist/js/targeting"));
var _utils = _interopRequireDefault(require("./dist/js/utils"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
/* eslint valid-jsdoc: 0 */

@@ -10,16 +35,15 @@ function Ads() {

}
} // bung all our modules on the protoype
}
_config.default.init = _config.init;
_config.default.clear = _config.clear; // bung all our modules on the protoype
Ads.prototype.config = require("./dist/js/config");
Ads.prototype.slots = require("./dist/js/slots");
Ads.prototype.gpt = require("./dist/js/ad-servers/gpt");
Ads.prototype.krux = require("./dist/js/data-providers/krux");
Ads.prototype.api = require("./dist/js/data-providers/api");
Ads.prototype.moat = require("./dist/js/data-providers/moat");
const targeting = require("./dist/js/targeting");
Ads.prototype.targeting = targeting;
Ads.prototype.utils = require("./dist/js/utils");
Ads.prototype.config = _config.default;
Ads.prototype.slots = _slots.default;
Ads.prototype.gpt = _gpt.default;
Ads.prototype.krux = _krux.default;
Ads.prototype.api = _api.default;
Ads.prototype.moat = _moat.default;
Ads.prototype.targeting = _targeting.default;
Ads.prototype.utils = _utils.default;
/**

@@ -33,5 +57,6 @@ * Initialises the ads library and all sub modules

this.config.init();
this.config(Object.assign(options, {
const configOptions = Object.assign(options, {
nonPersonalized: !options.disableConsentCookie
}));
});
this.config(configOptions);

@@ -103,3 +128,3 @@ if (options.disableConsentCookie) {

this.gpt.init();
this.krux.init(targeting);
this.krux.init(_targeting.default);

@@ -143,3 +168,3 @@ if (this.consents.behavioral) {

this.utils.log.warn('DEPRECATION NOTICE: Ads.version() will be deprecated in favour of Ads.getVersion()');
this.utils.log(`o-ads version: ${this.utils.getVersion()}`);
this.utils.log("o-ads version: ".concat(this.utils.getVersion()));
};

@@ -189,2 +214,4 @@

const ads = new Ads();
module.exports = ads;
var _default = ads;
exports.default = _default;
module.exports = exports.default;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _config = _interopRequireDefault(require("../config"));
var _utils = _interopRequireDefault(require("../utils"));
var _targeting = _interopRequireDefault(require("../targeting"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*globals googletag: true */

@@ -9,12 +22,6 @@

* @fileOverview
* ad server modukes for o-ads implementing Google publisher tags ad requests.
* ad server modules for o-ads implementing Google publisher tags ad requests.
*
* @author Robin Marr, robin.marr@ft.com
*/
const config = require("../config");
const utils = require("../utils");
const targeting = require("../targeting");
const DEFAULT_COLLAPSE_MODE = 'never';

@@ -33,9 +40,14 @@ let breakpoints = false;

function init() {
const gptConfig = config('gpt') || {};
breakpoints = config('responsive');
const gptConfig = (0, _config.default)('gpt') || {};
breakpoints = (0, _config.default)('responsive');
initGoogleTag();
utils.on('ready', onReady.bind(null, slotMethods));
utils.on('render', onRender);
utils.on('refresh', onRefresh);
utils.on('resize', onResize);
_utils.default.on('ready', onReady.bind(null, slotMethods));
_utils.default.on('render', onRender);
_utils.default.on('refresh', onRefresh);
_utils.default.on('resize', onResize);
googletag.cmd.push(setup.bind(null, gptConfig));

@@ -58,6 +70,6 @@ }

utils.attach('//www.googletagservices.com/tag/js/gpt.js', true, () => {
utils.broadcast('adServerLoadSuccess');
_utils.default.attach('//www.googletagservices.com/tag/js/gpt.js', true, () => {
_utils.default.broadcast('adServerLoadSuccess');
}, err => {
utils.broadcast('adServerLoadError', err);
_utils.default.broadcast('adServerLoadError', err);
});

@@ -79,7 +91,7 @@ }

function setup(gptConfig) {
const nonPersonalized = config('nonPersonalized') ? 1 : 0;
const nonPersonalized = (0, _config.default)('nonPersonalized') ? 1 : 0;
googletag.pubads().addEventListener('slotRenderEnded', onRenderEnded);
enableCompanions(gptConfig);
setRenderingMode(gptConfig);
setPageTargeting(targeting.get());
setPageTargeting(_targeting.default.get());
setPageCollapseEmpty();

@@ -117,3 +129,3 @@ googletag.enableServices();

function setPageTargeting(targetingData) {
if (utils.isPlainObject(targetingData)) {
if (_utils.default.isPlainObject(targetingData)) {
googletag.cmd.push(() => {

@@ -126,3 +138,3 @@ const pubads = googletag.pubads();

} else {
utils.log.warn('invalid targeting object passed', targetingData);
_utils.default.log.warn('invalid targeting object passed', targetingData);
}

@@ -139,3 +151,4 @@

if (!window.googletag) {
utils.log.warn('Attempting to clear page targeting before the GPT library has initialized');
_utils.default.log.warn('Attempting to clear page targeting before the GPT library has initialized');
return;

@@ -145,3 +158,4 @@ }

if (!key) {
utils.log.warn('Refusing to unset all keys - a key must be specified');
_utils.default.log.warn('Refusing to unset all keys - a key must be specified');
return;

@@ -163,3 +177,3 @@ }

function setPageCollapseEmpty() {
const mode = config('collapseEmpty');
const mode = (0, _config.default)('collapseEmpty');

@@ -204,4 +218,5 @@ if (mode === 'before') {

utils.extend(slot, slotMethods); // setup the gpt configuration the ad
_utils.default.extend(slot, slotMethods); // setup the gpt configuration the ad
googletag.cmd.push(() => {

@@ -225,3 +240,3 @@ slot.defineSlot().addServices().setCollapseEmpty().setTargeting().setURL();

if (utils.isFunction(slot.display)) {
if (_utils.default.isFunction(slot.display)) {
slot.display();

@@ -239,3 +254,3 @@ }

if (utils.isPlainObject(targeting)) {
if (_utils.default.isPlainObject(targeting)) {
Object.keys(targeting).forEach(name => {

@@ -268,3 +283,3 @@ event.detail.slot.gpt.slot.setTargeting(name, targeting[name]);

const domId = gptSlotId.getDomId().split('-');
const iframeId = `google_ads_iframe_${gptSlotId.getId()}`;
const iframeId = "google_ads_iframe_".concat(gptSlotId.getId());
data.type = domId.pop();

@@ -287,6 +302,6 @@ data.name = domId.join('-');

} else {
utils.log.warn('No iFrame found matching GPT SlotID');
_utils.default.log.warn('No iFrame found matching GPT SlotID');
}
utils.broadcast('rendered', data);
_utils.default.broadcast('rendered', data);
}

@@ -307,3 +322,3 @@ /*

window.googletag.cmd.push(() => {
this.gpt.id = `${this.name}-gpt`;
this.gpt.id = "".concat(this.name, "-gpt");
this.inner.setAttribute('id', this.gpt.id);

@@ -313,3 +328,3 @@ this.setUnitName();

if (!this.outOfPage) {
if (breakpoints && utils.isObject(this.sizes)) {
if (breakpoints && _utils.default.isObject(this.sizes)) {
this.initResponsive();

@@ -336,3 +351,3 @@ this.gpt.slot = googletag.defineSlot(this.gpt.unitName, [], this.gpt.id).defineSizeMapping(this.gpt.sizes);

window.googletag.cmd.push(() => {
utils.on('breakpoint', event => {
_utils.default.on('breakpoint', event => {
const slot = event.detail.slot;

@@ -353,2 +368,3 @@ const screensize = event.detail.screensize;

}, this.container);
const mapping = googletag.sizeMapping();

@@ -382,3 +398,4 @@ Object.keys(breakpoints).forEach(breakpoint => {

window.googletag.cmd.push(() => {
utils.broadcast('gptDisplay');
_utils.default.broadcast('gptDisplay');
googletag.display(this.gpt.id);

@@ -395,8 +412,8 @@ });

let unitName;
const gpt = config('gpt') || {};
const gpt = (0, _config.default)('gpt') || {};
const attr = this.container.getAttribute('data-o-ads-gpt-unit-name');
if (utils.isNonEmptyString(attr)) {
if (_utils.default.isNonEmptyString(attr)) {
unitName = attr;
} else if (utils.isNonEmptyString(gpt.unitName)) {
} else if (_utils.default.isNonEmptyString(gpt.unitName)) {
unitName = gpt.unitName;

@@ -407,5 +424,5 @@ } else {

const zone = gpt.zone;
unitName = `/${network}`;
unitName += utils.isNonEmptyString(site) ? `/${site}` : '';
unitName += utils.isNonEmptyString(zone) ? `/${zone}` : '';
unitName = "/".concat(network);
unitName += _utils.default.isNonEmptyString(site) ? "/".concat(site) : '';
unitName += _utils.default.isNonEmptyString(zone) ? "/".concat(zone) : '';
}

@@ -423,3 +440,3 @@

window.googletag.cmd.push(() => {
const gpt = config('gpt') || {};
const gpt = (0, _config.default)('gpt') || {};
gptSlot = gptSlot || this.gpt.slot;

@@ -441,3 +458,3 @@ gptSlot.addService(googletag.pubads());

window.googletag.cmd.push(() => {
const mode = this.collapseEmpty || config('collapseEmpty') || DEFAULT_COLLAPSE_MODE;
const mode = this.collapseEmpty || (0, _config.default)('collapseEmpty') || DEFAULT_COLLAPSE_MODE;

@@ -456,26 +473,27 @@ if (mode === 'before') {

/* istanbul ignore next */
if (this.outOfPage && this.gpt.iframe) {
function getImpressionURL(iframe) {
const trackingUrlElement = iframe.contentWindow.document.querySelector('[data-o-ads-impression-url]');
function getImpressionURL(iframe) {
const trackingUrlElement = iframe.contentWindow.document.querySelector('[data-o-ads-impression-url]');
if (trackingUrlElement) {
return trackingUrlElement.dataset.oAdsImpressionUrl;
} else {
utils.log.warn('Impression URL not found, this is set via a creative template.');
return false;
}
if (trackingUrlElement) {
return trackingUrlElement.dataset.oAdsImpressionUrl;
} else {
_utils.default.log.warn('Impression URL not found, this is set via a creative template.');
return false;
}
}
if (this.outOfPage && this.gpt.iframe) {
const impressionURL = getImpressionURL(this.gpt.iframe);
/* istanbul ignore else */
/* istanbul ignore next */
if (impressionURL) {
utils.attach(impressionURL, true, () => {
utils.log.info('Impression Url requested');
_utils.default.attach(impressionURL, true, () => {
_utils.default.log.info('Impression Url requested');
}, () => {
utils.log.info('CORS request to submit an impression failed');
_utils.default.log.info('CORS request to submit an impression failed');
}, true);
}
} else {
utils.log.warn('Attempting to call submitImpression on a non-oop slot');
_utils.default.log.warn('Attempting to call submitImpression on a non-oop slot');
}

@@ -491,4 +509,4 @@ },

gptSlot = gptSlot || this.gpt.slot;
const canonical = config('canonical');
gptSlot.set('page_url', canonical ? canonical : utils.getLocation());
const canonical = (0, _config.default)('canonical');
gptSlot.set('page_url', canonical ? canonical : _utils.default.getLocation());
});

@@ -506,3 +524,3 @@ return this;

if (utils.isPlainObject(this.targeting)) {
if (_utils.default.isPlainObject(this.targeting)) {
Object.keys(this.targeting).forEach(param => {

@@ -529,3 +547,4 @@ gptSlot.setTargeting(param, this.targeting[param]);

function updateCorrelator() {
utils.log.warn('[DEPRECATED]: Updatecorrelator is being phased out by google and removed from o-ads in future releases.');
_utils.default.log.warn('[DEPRECATED]: Updatecorrelator is being phased out by google and removed from o-ads in future releases.');
googletag.cmd.push(() => {

@@ -538,3 +557,3 @@ googletag.pubads().updateCorrelator();

if (window.googletag) {
const params = utils.isPlainObject(override) ? override : targeting.get();
const params = _utils.default.isPlainObject(override) ? override : _targeting.default.get();

@@ -549,15 +568,10 @@ if (!override) {

} else {
utils.log.warn('Attempting to set page targeting before the GPT library has initialized');
_utils.default.log.warn('Attempting to set page targeting before the GPT library has initialized');
}
}
module.exports.init = init;
module.exports.updateCorrelator = updateCorrelator;
module.exports.updatePageTargeting = updatePageTargeting;
module.exports.clearPageTargetingForKey = clearPageTargetingForKey;
function debug() {
const log = _utils.default.log;
const conf = (0, _config.default)('gpt');
module.exports.debug = () => {
const log = utils.log;
const conf = config('gpt');
if (!conf) {

@@ -570,2 +584,12 @@ return;

log.end();
};
}
var _default = {
init,
updateCorrelator,
updatePageTargeting,
clearPageTargetingForKey,
debug
};
exports.default = _default;
module.exports = exports.default;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.clear = exports.init = exports.default = void 0;
var _utils = _interopRequireDefault(require("./utils"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//TODO remove all ft.com specific stuff so we can remove this as a global

@@ -26,8 +35,6 @@ // currently all FT specific stuff is wrapped in an if window.FT

*/
const utils = require("./utils");
/**
* Default configuration set in the constructor.
*/
const defaults = {

@@ -93,3 +100,3 @@ formats: {

scripts.forEach(script => {
results = window.JSON ? utils.extend(results, JSON.parse(script.innerHTML)) : 'UNSUPPORTED';
results = window.JSON ? _utils.default.extend(results, JSON.parse(script.innerHTML)) : 'UNSUPPORTED';
});

@@ -131,4 +138,5 @@ return results;

if (utils.isPlainObject(k)) {
utils.extend(true, this.store, k);
if (_utils.default.isPlainObject(k)) {
_utils.default.extend(true, this.store, k);
result = this.store;

@@ -158,3 +166,3 @@ } else if (typeof v === 'undefined') {

Config.prototype.init = function () {
this.store = utils.extend(true, {}, defaults, fetchCanonicalURL(), fetchDeclaritiveConfig());
this.store = _utils.default.extend(true, {}, defaults, fetchCanonicalURL(), fetchDeclaritiveConfig());
return this.store;

@@ -164,4 +172,9 @@ };

const config = new Config();
module.exports = config.access.bind(config);
module.exports.init = config.init.bind(config);
module.exports.clear = config.clear.bind(config);
var _default = config.access.bind(config);
exports.default = _default;
const init = config.init.bind(config);
exports.init = init;
const clear = config.clear.bind(config);
exports.clear = clear;
"use strict";
const utils = require("../utils");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _utils = _interopRequireDefault(require("../utils"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function Api() {

@@ -35,3 +42,4 @@ this.data = [];

Api.prototype.handleResponse = function (response) {
utils.broadcast('apiRequestsComplete');
_utils.default.broadcast('apiRequestsComplete');
this.data = response;

@@ -89,2 +97,5 @@

module.exports = new Api();
var _default = new Api();
exports.default = _default;
module.exports = exports.default;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _utils = _interopRequireDefault(require("../utils"));
var _config = _interopRequireDefault(require("../config"));
var _domDelegate = require("dom-delegate");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* eslint new-cap: 0 */
const utils = require("../utils");
const config = require("../config");
const Delegate = require("dom-delegate");
/**

@@ -14,4 +23,2 @@ * The Krux class defines an FT.ads.krux instance

*/
function Krux() {

@@ -22,3 +29,3 @@ this.customAttributes = {};

Krux.prototype.add = function (target) {
utils.extend(true, this.customAttributes, target);
_utils.default.extend(true, this.customAttributes, target);
};

@@ -40,3 +47,3 @@

Krux.prototype.init = function (targeting) {
this.config = config('krux');
this.config = (0, _config.default)('krux');

@@ -60,4 +67,5 @@ if (this.config && this.config.id) {

let src;
const m = utils.getLocation().match(/\bkxsrc=([^&]+)/);
const m = _utils.default.getLocation().match(/\bkxsrc=([^&]+)/);
if (m) {

@@ -67,7 +75,7 @@ src = decodeURIComponent(m[1]);

const finalSrc = /^https?:\/\/([^\/]+\.)?krxd\.net(:\d{1,5})?\//i.test(src) ? src : src === "disable" ? "" : `//cdn.krxd.net/controltag/${this.config.id}.js`;
const finalSrc = /^https?:\/\/([^\/]+\.)?krxd\.net(:\d{1,5})?\//i.test(src) ? src : src === "disable" ? "" : "//cdn.krxd.net/controltag/".concat(this.config.id, ".js");
const loadKruxScript = () => {
this.kruxScript = utils.attach(finalSrc, true, () => {
utils.broadcast('kruxScriptLoaded');
this.kruxScript = _utils.default.attach(finalSrc, true, () => {
_utils.default.broadcast('kruxScriptLoaded');
});

@@ -85,3 +93,4 @@ this.events.init();

targeting.add(this.targeting());
utils.on('kruxScriptLoaded', this.consents);
_utils.default.on('kruxScriptLoaded', this.consents);
} else {// can't initialize Krux because no Krux ID is configured, please add it as key id in krux config.

@@ -100,3 +109,3 @@ }

let value;
name = `kx${name}`;
name = "kx".concat(name);
/* istanbul ignore else */

@@ -106,4 +115,4 @@

value = localStorage.getItem(name);
} else if (utils.cookie(name)) {
value = utils.cookie(name);
} else if (_utils.default.cookie(name)) {
value = _utils.default.cookie(name);
}

@@ -141,4 +150,4 @@

if (config('krux').limit) {
segs = segs.slice(0, config('krux').limit);
if ((0, _config.default)('krux').limit) {
segs = segs.slice(0, (0, _config.default)('krux').limit);
}

@@ -180,3 +189,3 @@ }

window.addEventListener('load', function () {
const delEvnt = new Delegate(document.body);
const delEvnt = new _domDelegate.Delegate(document.body);

@@ -199,3 +208,3 @@ for (const kEvnt in config) {

if (id) {
attrs = utils.isPlainObject(attrs) ? attrs : {};
attrs = _utils.default.isPlainObject(attrs) ? attrs : {};
return window.Krux('admEvent', id, attrs); // eslint-disable-line new-cap

@@ -209,11 +218,11 @@ }

let event;
const configured = config('krux') && config('krux').events;
const configured = (0, _config.default)('krux') && (0, _config.default)('krux').events;
/* istanbul ignore else */
if (utils.isPlainObject(configured)) {
if (_utils.default.isPlainObject(configured)) {
for (event in configured) {
/* istanbul ignore else */
if (utils.isFunction(this[event])) {
if (_utils.default.isFunction(this[event])) {
this[event](configured[event]);
} else if (utils.isFunction(configured[event].fn)) {
} else if (_utils.default.isFunction(configured[event].fn)) {
configured[event].fn(configured[event]);

@@ -247,3 +256,3 @@ }

Object.keys(this.customAttributes[type]).forEach(key => {
window.Krux('set', type === 'custom' ? key : `${type}_attr_${key}`, null);
window.Krux('set', type === 'custom' ? key : "".concat(type, "_attr_").concat(key), null);
});

@@ -256,8 +265,9 @@ }

Krux.prototype.consents = function () {
if (config('krux') && config('krux').consentState) {
utils.broadcast('kruxConsentOptinOK');
if ((0, _config.default)('krux') && (0, _config.default)('krux').consentState) {
_utils.default.broadcast('kruxConsentOptinOK');
const kuid = localStorage && localStorage.getItem('kxkuid');
if (kuid) {
const consentApi = `https://consumer.krxd.net/consent/set/bcbe1a6d-fa90-4db5-b4dc-424c69802310?idt=device&dt=kxcookie&dc=1&al=1&tg=1&cd=1&sh=1&re=1&idv=${kuid}`;
const consentApi = "https://consumer.krxd.net/consent/set/bcbe1a6d-fa90-4db5-b4dc-424c69802310?idt=device&dt=kxcookie&dc=1&al=1&tg=1&cd=1&sh=1&re=1&idv=".concat(kuid);
fetch(consentApi, {

@@ -267,3 +277,4 @@ timeout: 2000

if (data.ok) {
utils.broadcast('kruxKuidAck');
_utils.default.broadcast('kruxKuidAck');
return;

@@ -274,4 +285,5 @@ }

}).catch(() => {
utils.broadcast('kruxKuidError');
Promise.resolve(utils.log.warn('Fetch request failed to GET krux consent api'));
_utils.default.broadcast('kruxKuidError');
Promise.resolve(_utils.default.log.warn('Fetch request failed to GET krux consent api'));
});

@@ -282,3 +294,3 @@ } else {

} else {
utils.broadcast('kruxConsentOptinFailed');
_utils.default.broadcast('kruxConsentOptinFailed');
}

@@ -290,3 +302,3 @@ };

Object.keys(this.customAttributes[type]).forEach(key => {
window.Krux('set', type === 'custom' ? key : `${type}_attr_${key}`, null);
window.Krux('set', type === 'custom' ? key : "".concat(type, "_attr_").concat(key), null);
});

@@ -298,3 +310,3 @@ delete this.customAttributes[type];

Krux.prototype.debug = function () {
const log = utils.log;
const log = _utils.default.log;

@@ -312,3 +324,4 @@ if (!this.config) {

const attrs = utils.extend(true, this.config.attributes, this.customAttributes);
const attrs = _utils.default.extend(true, this.config.attributes, this.customAttributes);
const keys = Object.keys(attrs);

@@ -319,3 +332,3 @@

keys.forEach(key => {
log.start(`${key}`);
log.start("".concat(key));
log.attributeTable(attrs[key]);

@@ -343,3 +356,3 @@ log.end();

if (tags.length) {
log.start(`${tags.length} Supertag© scripts`);
log.start("".concat(tags.length, " Supertag\xA9 scripts"));
tags.forEach(function (tag) {

@@ -354,2 +367,5 @@ log(tag.dataset.alias, tag.querySelector("script"));

module.exports = new Krux();
var _default = new Krux();
exports.default = _default;
module.exports = exports.default;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _utils = _interopRequireDefault(require("../utils"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**

@@ -11,4 +20,2 @@ * we use a third party script from moat to determine invalid traffic.

*/
const utils = require("../utils");
const Moat = function Moat() {}; // eslint-disable-line no-empty-function

@@ -33,3 +40,3 @@

const fireCompleteEvent = () => {
utils.broadcast('moatIVTcomplete');
_utils.default.broadcast('moatIVTcomplete');
};

@@ -41,2 +48,5 @@

module.exports = new Moat();
var _default = new Moat();
exports.default = _default;
module.exports = exports.default;
"use strict";
const utils = require("./utils");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
const config = require("./config");
var _utils = _interopRequireDefault(require("./utils"));
var _config = _interopRequireDefault(require("./config"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const VALID_SIZE_STRINGS = ['fluid'];

@@ -15,3 +22,3 @@ const VALID_COLLAPSE_MODES = ['before', 'after', 'never'];

/* istanbul ignore else */
else if (utils.isArray(_sizes)) {
else if (_utils.default.isArray(_sizes)) {
const regex = /(\d+)x(\d+)/;

@@ -35,4 +42,4 @@ value.split(',').filter(size => size.length).forEach(size => {

} else {
const mapping = config().formats;
const formats = utils.isArray(value) ? value : value.split(',');
const mapping = (0, _config.default)().formats;
const formats = _utils.default.isArray(value) ? value : value.split(',');
formats.forEach(format => {

@@ -42,3 +49,3 @@ if (mapping && mapping[format]) {

if (utils.isArray(format.sizes[0]) || VALID_SIZE_STRINGS.indexOf(format.sizes[0]) >= 0) {
if (_utils.default.isArray(format.sizes[0]) || VALID_SIZE_STRINGS.indexOf(format.sizes[0]) >= 0) {
format.sizes.forEach(size => {

@@ -51,3 +58,3 @@ sizes.push(size);

} else {
utils.log.error(`Slot configured with unknown format ${format}`);
_utils.default.log.error("Slot configured with unknown format ".concat(format));
}

@@ -63,3 +70,3 @@ });

if (!utils.isPlainObject(sizes)) {
if (!_utils.default.isPlainObject(sizes)) {
sizes = {};

@@ -75,3 +82,3 @@ }

if (!utils.isPlainObject(sizes)) {
if (!_utils.default.isPlainObject(sizes)) {
sizes = {};

@@ -87,4 +94,6 @@ }

targeting: function targeting(value, _targeting) {
value = utils.hash(value, ';', '=');
utils.extend(_targeting, value);
value = _utils.default.hash(value, ';', '=');
_utils.default.extend(_targeting, value);
return _targeting;

@@ -106,3 +115,4 @@ },

if (isUnknownAttribute) {
utils.log.warn(`Invalid attribute ${value} used for collapse-empty attribute, please use 'before', 'after' or 'never'`);
_utils.default.log.warn("Invalid attribute ".concat(value, " used for collapse-empty attribute, please use 'before', 'after' or 'never'"));
return undefined;

@@ -141,5 +151,5 @@ }

const renderEvent = 'rendered';
const cfg = config();
let slotConfig = config('slots') || {};
const disableSwipeDefault = config('disableSwipeDefault') || false; // store the container
const cfg = (0, _config.default)();
let slotConfig = (0, _config.default)('slots') || {};
const disableSwipeDefault = (0, _config.default)('disableSwipeDefault') || false; // store the container

@@ -178,5 +188,5 @@ this.container = container; // the current responsive screensize

if (utils.isArray(slotConfig.formats)) {
if (_utils.default.isArray(slotConfig.formats)) {
attributeParsers.formats(slotConfig.formats, this.sizes);
} else if (utils.isPlainObject(slotConfig.formats)) {
} else if (_utils.default.isPlainObject(slotConfig.formats)) {
this.sizes = {};

@@ -191,3 +201,3 @@ Object.keys(slotConfig.formats).forEach(screenName => {

} else {
this.lazyLoad = config('lazyLoad') || false;
this.lazyLoad = (0, _config.default)('lazyLoad') || false;
}

@@ -198,3 +208,3 @@

if (outerEl && cfg.displayLabelWithBorders && this.container.getAttribute('data-o-ads-label')) {
utils.once(renderEvent, () => {
_utils.default.once(renderEvent, () => {
outerEl.classList.add('o-ads--label-with-borders');

@@ -208,4 +218,5 @@ });

if (!this.sizes.length && !utils.isPlainObject(this.sizes)) {
utils.log.error('slot %s has no configured sizes!', this.name);
if (!this.sizes.length && !_utils.default.isPlainObject(this.sizes)) {
_utils.default.log.error('slot %s has no configured sizes!', this.name);
return false;

@@ -228,3 +239,4 @@ } // Either retrieve the existing IntersectionObserver, or tell slots.js to create a new one.

Array.from(this.container.attributes).forEach(attribute => {
const name = utils.parseAttributeName(attribute.name);
const name = _utils.default.parseAttributeName(attribute.name);
const value = attribute.value;

@@ -257,3 +269,3 @@

Array.from(this.container.attributes).forEach(attribute => {
attributes[utils.parseAttributeName(attribute)] = attribute.value;
attributes[_utils.default.parseAttributeName(attribute)] = attribute.value;
});

@@ -277,3 +289,3 @@ this.attributes = attributes;

if (this.companion) {
utils.once('masterLoaded', () => {
_utils.default.once('masterLoaded', () => {
if (this.hasValidSize()) {

@@ -305,3 +317,3 @@ this.render();

/* istanbul ignore else */
if (utils.isPlainObject(this.sizes)) {
if (_utils.default.isPlainObject(this.sizes)) {
/* istanbul ignore else */

@@ -312,3 +324,3 @@ if (!this.hasValidSize()) {

utils.on('breakpoint', onChangeBreakpoint, this.container);
_utils.default.on('breakpoint', onChangeBreakpoint, this.container);
}

@@ -339,3 +351,3 @@

if (!this.name) {
this.name = `o-ads-slot-${Math.floor(Math.random() * 10000)}`;
this.name = "o-ads-slot-".concat(Math.floor(Math.random() * 10000));
this.container.setAttribute('data-o-ads-name', this.name);

@@ -354,4 +366,6 @@ }

this.setFormatLoaded(false);
document.body.classList.add(`o-ads-no-${this.name}`);
utils.broadcast('collapsed', this);
document.body.classList.add("o-ads-no-".concat(this.name));
_utils.default.broadcast('collapsed', this);
return this;

@@ -375,3 +389,3 @@ };

this.container.classList.remove('o-ads--empty');
document.body.classList.remove(`o-ads-no-${this.name}`);
document.body.classList.remove("o-ads-no-".concat(this.name));
return this;

@@ -386,3 +400,3 @@ };

/* istanbul ignore else */
if (utils.isFunction(this['clearSlot'])) {
if (_utils.default.isFunction(this['clearSlot'])) {
this.clearSlot();

@@ -400,4 +414,5 @@ }

/* istanbul ignore else */
if (utils.isFunction(this['destroySlot'])) {
utils.off('breakpoint', onChangeBreakpoint, this.container);
if (_utils.default.isFunction(this['destroySlot'])) {
_utils.default.off('breakpoint', onChangeBreakpoint, this.container);
this.destroySlot();

@@ -416,3 +431,3 @@ this.container.removeChild(this.outer);

/* istanbul ignore else */
if (utils.isFunction(this['submitGptImpression'])) {
if (_utils.default.isFunction(this['submitGptImpression'])) {
this.submitGptImpression();

@@ -434,7 +449,8 @@ }

if (utils.isPlainObject(data)) {
utils.extend(details, data);
if (_utils.default.isPlainObject(data)) {
_utils.default.extend(details, data);
}
utils.broadcast(name, details, this.container);
_utils.default.broadcast(name, details, this.container);
return this;

@@ -454,3 +470,3 @@ };

const value = attrs[attr];
container += `${attr}=${value} `;
container += "".concat(attr, "=").concat(value, " ");
});

@@ -467,3 +483,3 @@ }

if (screensize && utils.isPlainObject(this.sizes)) {
if (screensize && _utils.default.isPlainObject(this.sizes)) {
return this.sizes[screensize] !== false;

@@ -500,4 +516,4 @@ }

if (className && !config('displayLabelWithBorders')) {
this.container.classList.add(`o-ads--${className}`);
if (className && !(0, _config.default)('displayLabelWithBorders')) {
this.container.classList.add("o-ads--".concat(className));
}

@@ -508,2 +524,4 @@

module.exports = Slot;
var _default = Slot;
exports.default = _default;
module.exports = exports.default;
"use strict";
/* eslint no-inner-declarations: 1 */
const utils = require("./utils");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
const config = require("./config");
var _utils = _interopRequireDefault(require("./utils"));
const Slot = require("./slot");
var _config = _interopRequireDefault(require("./config"));
var _slot = _interopRequireDefault(require("./slot"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* eslint no-inner-declarations: 1 */
let screensize = null;

@@ -26,5 +33,5 @@ /**

if (utils.isNonEmptyString(names)) {
if (_utils.default.isNonEmptyString(names)) {
slots.push(names);
} else if (utils.isArray(names)) {
} else if (_utils.default.isArray(names)) {
slots = names;

@@ -35,3 +42,3 @@ }

if (utils.isFunction(callback)) {
if (_utils.default.isFunction(callback)) {
callback.call(this, slots);

@@ -53,13 +60,13 @@ }

if (slot) {
if (utils.isFunction(slot[action])) {
if (_utils.default.isFunction(slot[action])) {
slot[action]();
} else {
if (utils.isFunction(slot.fire)) {
if (_utils.default.isFunction(slot.fire)) {
slot.fire(action);
} else {
utils.log.warn('Attempted to %s on a non-slot %s', action, name);
_utils.default.log.warn('Attempted to %s on a non-slot %s', action, name);
}
}
} else {
utils.log.warn('Attempted to %s non-existant slot %s', action, name);
_utils.default.log.warn('Attempted to %s non-existant slot %s', action, name);
}

@@ -73,3 +80,3 @@ }

const formats = config('formats');
const formats = (0, _config.default)('formats');

@@ -80,3 +87,3 @@ for (const prop in formats) {

let sizes = formats[prop].sizes;
sizes = utils.isArray(sizes[0]) ? sizes : [sizes];
sizes = _utils.default.isArray(sizes[0]) ? sizes : [sizes];
const match = sizes.filter(function (s) {

@@ -153,4 +160,4 @@ return s[0] === parseInt(size[0], 10) && s[1] === parseInt(size[1], 10);

// find the element and remove the ID in favour of a data attribute
if (utils.isString(container)) {
container = document.getElementById(container) || document.querySelector(`[data-o-ads-name="${container}"]`);
if (_utils.default.isString(container)) {
container = document.getElementById(container) || document.querySelector("[data-o-ads-name=\"".concat(container, "\"]"));

@@ -164,4 +171,5 @@ if (container && container.id) {

if (!utils.isElement(container)) {
utils.log.error('slot container must be an element!', container);
if (!_utils.default.isElement(container)) {
_utils.default.log.error('slot container must be an element!', container);
return false;

@@ -173,3 +181,3 @@ } // add the aria hidden attribute

const slot = new Slot(container, screensize, this.initLazyLoading.bind(this));
const slot = new _slot.default(container, screensize, this.initLazyLoading.bind(this));
/* istanbul ignore else */

@@ -181,3 +189,3 @@

} else if (this[slot.name]) {
utils.log.error('slot %s is already defined!', slot.name);
_utils.default.log.error('slot %s is already defined!', slot.name);
}

@@ -189,4 +197,4 @@

Slots.prototype.initRefresh = function () {
if (config('flags').refresh && config('refresh')) {
const data = config('refresh');
if ((0, _config.default)('flags').refresh && (0, _config.default)('refresh')) {
const data = (0, _config.default)('refresh');
this.refreshCount = 0;

@@ -218,3 +226,3 @@ /* istanbul ignore else */

Slots.prototype.initRendered = function () {
utils.on('rendered', function (slots, event) {
_utils.default.on('rendered', function (slots, event) {
const slot = slots[event.detail.name];

@@ -224,3 +232,4 @@ /* istanbul ignore else */

if (slot) {
utils.extend(slot[slot.server], event.detail[slot.server]);
_utils.default.extend(slot[slot.server], event.detail[slot.server]);
const size = event.detail.gpt.size;

@@ -233,2 +242,3 @@ const format = findFormatBySize(size);

}.bind(null, this));
return this;

@@ -242,7 +252,7 @@ };

Slots.prototype.initResponsive = function () {
const breakpoints = config('responsive');
const breakpoints = (0, _config.default)('responsive');
/* istanbul ignore else */
if (utils.isObject(breakpoints)) {
screensize = utils.responsive(breakpoints, onBreakpointChange.bind(null, this));
if (_utils.default.isObject(breakpoints)) {
screensize = _utils.default.responsive(breakpoints, onBreakpointChange.bind(null, this));
}

@@ -288,15 +298,19 @@

function pmHandler(slots, event) {
const data = utils.messenger.parse(event.data);
const data = _utils.default.messenger.parse(event.data);
/* istanbul ignore else don't process messages with a non oAds type*/
if (data.type && (/^oAds\./.test(data.type) || /^touch/.test(data.type))) {
const type = data.type.replace('oAds\.', ''); // Make sure the message is coming from an identified ad slot
const slotName = utils.iframeToSlotName(event.source.window);
const slotName = _utils.default.iframeToSlotName(event.source.window);
const slot = slots[slotName] || false;
if (!slot) {
utils.log.error('Message received from unidentified slot');
_utils.default.log.error('Message received from unidentified slot');
return;
} // For backwards compatibility with o-ads-embed v2
// TODO: remove once creative wrapper updated with o-ads-embed v3

@@ -313,3 +327,4 @@

};
utils.messenger.post(messageToSend, event.source);
_utils.default.messenger.post(messageToSend, event.source);
} // TODO: Remove adIframeLoaded once we can tag onto GPTs `slotRenderEnded` event

@@ -327,3 +342,3 @@ else if (type === 'adIframeLoaded') {

} else {
utils.log.error('Unknown message received from o-ads-embed');
_utils.default.log.error('Unknown message received from o-ads-embed');
}

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

Slots.prototype.initLazyLoading = function (slotConfig) {
const lazyLoadingConfig = config('lazyLoad') || slotConfig | {};
const lazyLoadingConfig = (0, _config.default)('lazyLoad') || slotConfig | {};
this.lazyLoadingObservers = this.lazyLoadingObservers || [];

@@ -351,25 +366,25 @@ this.flushLazyLoading(); // find any pre-existing observers

return lazyLoadingConfig.root == observer.root; // eslint-disable-line eqeqeq
}); // If we don't already have an instance of the observer, and it is enabled globally or on a slot (force), then create one.
});
function onChange(changes) {
//Execute the changes in the order they appear on the page. This is because the top slot often determines what the lower slots display.
/* istanbul ignore next */
changes.filter(a => a.intersectionRect.height || a.intersectionRect.width || a.intersectionRect.top || a.intersectionRect.left).sort((a, b) => a.intersectionRect.top - b.intersectionRect.top).forEach(change => {
const slotName = change.target.getAttribute('data-o-ads-name');
/* istanbul ignore else */
if (slotName) {
invokeMethodOnSlots.call(this, slotName, 'render');
}
});
} // If we don't already have an instance of the observer, and it is enabled globally or on a slot (force), then create one.
/* istanbul ignore else */
if ('IntersectionObserver' in window && !lazyLoadingObserver && Boolean(lazyLoadingConfig)) {
const options = {};
function onChange(changes) {
//Execute the changes in the order they appear on the page. This is because the top slot often determines what the lower slots display.
/* istanbul ignore next */
changes.filter(a => a.intersectionRect.height || a.intersectionRect.width || a.intersectionRect.top || a.intersectionRect.left).sort((a, b) => a.intersectionRect.top - b.intersectionRect.top).forEach(change => {
const slotName = change.target.getAttribute('data-o-ads-name');
/* istanbul ignore else */
if (slotName) {
invokeMethodOnSlots.call(this, slotName, 'render');
}
});
}
/* istanbul ignore else */
if (typeof lazyLoadingConfig === 'object') {

@@ -402,3 +417,3 @@ /* istanbul ignore else */

if (slot instanceof Slot) {
if (slot instanceof _slot.default) {
fn.call(this, slot);

@@ -423,3 +438,3 @@ }

Slots.prototype.debug = function () {
const log = utils.log;
const log = _utils.default.log;
const data = [];

@@ -432,8 +447,8 @@ this.forEach(function (slot) {

'line item id': slot.gpt.lineItemId || 'N/A',
size: utils.isArray(slot.gpt.size) && slot.gpt.size.join('×') || slot.gpt.isEmpty && 'empty' || 'N/A',
sizes: utils.isArray(slot.sizes) && slot.sizes.map(function (item) {
size: _utils.default.isArray(slot.gpt.size) && slot.gpt.size.join('×') || slot.gpt.isEmpty && 'empty' || 'N/A',
sizes: _utils.default.isArray(slot.sizes) && slot.sizes.map(function (item) {
return item.join('×');
}).join(', ') || 'responsive slot',
targeting: Object.keys(slot.targeting).map(function (param) {
return `${param}=${slot.targeting[param]}`;
return "".concat(param, "=").concat(slot.targeting[param]);
}).join(', ')

@@ -448,2 +463,5 @@ };

module.exports = new Slots();
var _default = new Slots();
exports.default = _default;
module.exports = exports.default;
"use strict";
const config = require("./config");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
const utils = require("./utils");
var _config = _interopRequireDefault(require("./config"));
var _utils = _interopRequireDefault(require("./utils"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
let parameters = {};

@@ -18,8 +25,9 @@

};
utils.extend(parameters, this.getFromConfig(), this.searchTerm(), this.socialFlow(), this.getVersion());
_utils.default.extend(parameters, this.getFromConfig(), this.searchTerm(), this.socialFlow(), this.getVersion());
for (const item in methods) {
/* istanbul ignore else */
if (methods.hasOwnProperty(item)) {
utils.extend(parameters, methods[item]());
_utils.default.extend(parameters, methods[item]());
}

@@ -33,4 +41,4 @@ }

/* istanbul ignore else */
if (utils.isPlainObject(obj)) {
utils.extend(parameters, obj);
if (_utils.default.isPlainObject(obj)) {
_utils.default.extend(parameters, obj);
}

@@ -56,8 +64,8 @@ };

Targeting.prototype.getFromConfig = function () {
let targeting = config('dfp_targeting') || {};
let targeting = (0, _config.default)('dfp_targeting') || {};
if (!utils.isPlainObject(targeting)) {
if (!_utils.default.isPlainObject(targeting)) {
/* istanbul ignore else */
if (utils.isString(targeting)) {
targeting = utils.hash(targeting, ';', '=');
if (_utils.default.isString(targeting)) {
targeting = _utils.default.hash(targeting, ';', '=');
}

@@ -70,5 +78,5 @@ }

Targeting.prototype.getVersion = function () {
if (config('passOAdsVersion')) {
if ((0, _config.default)('passOAdsVersion')) {
return {
OADS_VERSION: utils.getVersion()
OADS_VERSION: _utils.default.getVersion()
};

@@ -84,3 +92,3 @@ }

Targeting.prototype.socialFlow = function () {
const sf = utils.getQueryParamByName('socialflow');
const sf = _utils.default.getQueryParamByName('socialflow');

@@ -96,4 +104,6 @@ if (sf) {

let codedValue;
const referrer = utils.getReferrer(); // TODO: add on.ft.com
const referrer = _utils.default.getReferrer(); // TODO: add on.ft.com
const lookup = {

@@ -108,3 +118,3 @@ 't.co': 'twi',

Object.keys(lookup).forEach(url => {
const refererRegex = new RegExp(`^http(|s):\/\/(www.)*(${url})`);
const refererRegex = new RegExp("^http(|s)://(www.)*(".concat(url, ")"));
/* istanbul ignore else */

@@ -122,3 +132,4 @@

Targeting.prototype.searchTerm = function () {
const qs = utils.hash(utils.getQueryString(), /\&|\;/, '=');
const qs = _utils.default.hash(_utils.default.getQueryString(), /\&|\;/, '=');
let keywords = qs.q || qs.s || qs.query || qs.queryText || qs.searchField || undefined;

@@ -138,3 +149,3 @@ /* istanbul ignore else */

return {
ts: utils.getTimestamp()
ts: _utils.default.getTimestamp()
};

@@ -144,4 +155,4 @@ };

Targeting.prototype.responsive = function () {
return config('responsive') ? {
res: utils.responsive.getCurrent()
return (0, _config.default)('responsive') ? {
res: _utils.default.responsive.getCurrent()
} : {};

@@ -151,3 +162,3 @@ };

Targeting.prototype.debug = function () {
const log = utils.log;
const log = _utils.default.log;
const parameters = this.get();

@@ -163,2 +174,5 @@ /* istanbul ignore else */

module.exports = new Targeting();
var _default = new Targeting();
exports.default = _default;
module.exports = exports.default;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.broadcast = broadcast;
exports.on = on;
exports.off = off;
exports.once = once;
/**

@@ -16,8 +24,6 @@ * Utility methods for o-ads events. Methods defined here are added to the utils object not the utils.event object.

*/
module.exports.broadcast = broadcast;
function broadcast(name, data, target) {
/* istanbul ignore next: ignore the final fallback as hard trigger */
target = target || document.body || document.documentElement;
name = `oAds.${name}`;
name = "oAds.".concat(name);
const opts = {

@@ -38,6 +44,4 @@ bubbles: true,

module.exports.on = on;
function on(name, callback, target) {
name = `oAds.${name}`;
name = "oAds.".concat(name);
/* istanbul ignore next: ignore the final fallback as hard trigger */

@@ -56,6 +60,4 @@

module.exports.off = off;
function off(name, callback, target) {
name = `oAds.${name}`;
name = "oAds.".concat(name);
/* istanbul ignore next: ignore the final fallback as hard trigger */

@@ -74,4 +76,2 @@

module.exports.once = once;
function once(name, callback, target) {

@@ -81,3 +81,3 @@ const handler = function handler(event) {

const targ = event.target || event.srcElement;
targ.removeEventListener(name = `oAds.${name}`, callback);
targ.removeEventListener(name = "oAds.".concat(name), callback);

@@ -84,0 +84,0 @@ if (callback) {

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.extend = extend;
exports.default = exports.getVersion = exports.cookie = exports.buildObjectFromArray = exports.iframeToSlotName = exports.getTimestamp = exports.getQueryParamByName = exports.getQueryString = exports.getLocation = exports.parseAttributeName = exports.dehyphenise = exports.getReferrer = exports.attach = exports.hash = exports.isElement = exports.isNonEmptyString = exports.isPlainObject = exports.isWindow = exports.isObject = exports.isStorage = exports.isFunction = exports.isString = exports.isArray = void 0;
var _events = require("./events");
var _messenger = _interopRequireDefault(require("./messenger"));
var _responsive = _interopRequireWildcard(require("./responsive"));
var _log = _interopRequireWildcard(require("./log"));
var _version = _interopRequireDefault(require("../version"));
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**

@@ -9,3 +29,11 @@ * Utility methods for the advertising library.

const hop = Object.prototype.hasOwnProperty;
const utils = module.exports;
_responsive.default.getCurrent = _responsive.getCurrent;
_log.default.start = _log.start;
_log.default.end = _log.end;
_log.default.isOn = _log.isOn;
_log.default.info = _log.info;
_log.default.warn = _log.warn;
_log.default.error = _log.error;
_log.default.table = _log.table;
_log.default.attributeTable = _log.attributeTable;
/**

@@ -32,35 +60,60 @@ * Uses object prototype toString method to get at the type of object we are dealing,

/**
* Creates a method for testing the type of an Object
* @private
* @param {string} The name of the object type to be tested e.g. Array
* @returns a method that takes any javascript object and tests if it is of
* the supplied className
* Test if an object is an Array
* @param {object} obj The object to be tested
* @returns {boolean} true if the object is of type Array, otherwise false
*/
function createIsTest(className) {
return function (obj) {
return is(obj) === className;
};
}
const isArray = function isArray(obj) {
return is(obj) === "Array";
};
/**
* Curries some useful is{ClassName} methods into the supplied Object
* @private
* @param {object} The object to add the methods too
* @param {array} A list of types to create methods for defaults to "Array", "Object", "String", "Function"
* @returns The object supplied in the first param with is{ClassName} Methods Added
* 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
*/
function curryIsMethods(obj, classNames) {
classNames = classNames || ['Array', 'Object', 'String', 'Function', 'Storage'];
exports.isArray = isArray;
while (classNames.length) {
const className = classNames.pop();
obj[`is${className}`] = createIsTest(className);
}
const isString = function isString(obj) {
return is(obj) === "String";
};
/**
* Test if an object is a Function
* @param {object} obj The object to be tested
* @returns {boolean} true if the object is of type Function, otherwise false
*/
return obj;
}
exports.isString = isString;
const isFunction = function isFunction(obj) {
return is(obj) === "Function";
};
/**
* 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
*/
exports.isFunction = isFunction;
const isStorage = function isStorage(obj) {
return is(obj) === "Storage";
};
/**
* Test if an object is an Object
* @param {object} obj The object to be tested
* @returns {boolean} true if the object is of type Object, otherwise false
*/
exports.isStorage = isStorage;
const isObject = function isObject(obj) {
return is(obj) === "Object";
};
/**
* Test if an object is the global window object

@@ -72,3 +125,5 @@ * @param {object} obj The object to be tested

module.exports.isWindow = function (obj) {
exports.isObject = isObject;
const isWindow = function isWindow(obj) {
return obj && obj !== null && obj === window;

@@ -85,3 +140,5 @@ };

module.exports.isPlainObject = function (obj) {
exports.isWindow = isWindow;
const isPlainObject = function isPlainObject(obj) {
const hop = Object.prototype.hasOwnProperty; // Must be an Object.

@@ -91,3 +148,3 @@ // Because of IE, we also have to check the presence of the constructor property.

if (!obj || !utils.isObject(obj) || obj.nodeType || utils.isWindow(obj)) {
if (!obj || !isObject(obj) || obj.nodeType || isWindow(obj)) {
return false;

@@ -123,21 +180,16 @@ }

module.exports.isNonEmptyString = function (str) {
return utils.isString(str) && Boolean(str.length);
exports.isPlainObject = isPlainObject;
const isNonEmptyString = function isNonEmptyString(str) {
return isString(str) && Boolean(str.length);
};
module.exports.isElement = function (element) {
exports.isNonEmptyString = isNonEmptyString;
const isElement = function isElement(element) {
return element && element.nodeType === 1 && element.tagName || false;
};
/**
* Merge or clone objects
* @function
* @param {boolean/object} deep/target If boolean specifies if this should be a deep copy or not, otherwise is the target object for the copy
* @param {object} target If deep copy is true will be the target object of the copy
* @param {object} objects All other params are objects to be merged into the target
* @returns {object} The target object extended with the other params
*/
exports.isElement = isElement;
module.exports.extend = extend;
function extend() {

@@ -167,3 +219,3 @@ /* jshint forin: false */

if (typeof target !== "object" && !utils.isFunction(target)) {
if (typeof target !== "object" && !isFunction(target)) {
target = {};

@@ -194,10 +246,10 @@ } // do nothing if only one argument is passed (or 2 for a deep copy)

if (deep && copy && (utils.isPlainObject(copy) || utils.isArray(copy))) {
copyIsArray = utils.isArray(copy);
if (deep && copy && (isPlainObject(copy) || isArray(copy))) {
copyIsArray = isArray(copy);
if (copyIsArray) {
copyIsArray = false;
clone = src && utils.isArray(src) ? src : [];
clone = src && isArray(src) ? src : [];
} else {
clone = src && utils.isObject(src) ? src : {};
clone = src && isObject(src) ? src : {};
} // Never move original objects, clone them

@@ -229,6 +281,6 @@

module.exports.hash = function (str, delimiter, pairing) {
const hash = function hash(str, delimiter, pairing) {
let pair;
let value;
const hash = {};
const hashObj = {};

@@ -243,3 +295,3 @@ if (str && str.split) {

if (pair.length > 1) {
hash[pair[0].trim()] = pair.slice(1).join(pairing);
hashObj[pair[0].trim()] = pair.slice(1).join(pairing);
}

@@ -249,3 +301,3 @@ }

return hash;
return hashObj;
};

@@ -264,3 +316,5 @@ /**

module.exports.attach = function (scriptUrl, async, callback, errorcb, autoRemove) {
exports.hash = hash;
const attach = function attach(scriptUrl, async, callback, errorcb, autoRemove) {
const tag = document.createElement('script');

@@ -293,3 +347,3 @@ const node = document.getElementsByTagName('script')[0];

if (utils.isFunction(callback)) {
if (isFunction(callback)) {
/* istanbul ignore if - legacy IE code, won't test */

@@ -311,3 +365,3 @@ if (hop.call(tag, 'onreadystatechange')) {

if (utils.isFunction(errorcb)) {
if (isFunction(errorcb)) {
tag.onerror = function () {

@@ -331,3 +385,5 @@ processCallback(errorcb);

module.exports.getReferrer = function () {
exports.attach = attach;
const getReferrer = function getReferrer() {
return document.referrer || '';

@@ -342,3 +398,5 @@ };

module.exports.dehyphenise = function (string) {
exports.getReferrer = getReferrer;
const dehyphenise = function dehyphenise(string) {
return string.replace(/(-)([a-z])/g, function (match, hyphen, letter) {

@@ -355,5 +413,7 @@ return letter.toUpperCase();

module.exports.parseAttributeName = function (attribute) {
const name = utils.isString(attribute) ? attribute : attribute.name;
return utils.dehyphenise(name.replace(/(data-)?o-ads-/, ''));
exports.dehyphenise = dehyphenise;
const parseAttributeName = function parseAttributeName(attribute) {
const name = isString(attribute) ? attribute : attribute.name;
return dehyphenise(name.replace(/(data-)?o-ads-/, ''));
};

@@ -369,3 +429,5 @@ /**

module.exports.getLocation = function () {
exports.parseAttributeName = parseAttributeName;
const getLocation = function getLocation() {
return document.location.href || '';

@@ -381,3 +443,5 @@ };

module.exports.getQueryString = function () {
exports.getLocation = getLocation;
const getQueryString = function getQueryString() {
return document.location.search.substring(1) || '';

@@ -393,3 +457,5 @@ };

module.exports.getQueryParamByName = function (name, url) {
exports.getQueryString = getQueryString;
const getQueryParamByName = function getQueryParamByName(name, url) {
url = url || window.location.href;

@@ -416,5 +482,7 @@ name = name.replace(/[\[\]]/g, "\\$&");

module.exports.getTimestamp = function () {
exports.getQueryParamByName = getQueryParamByName;
const getTimestamp = function getTimestamp() {
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("");
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("");
};

@@ -430,3 +498,5 @@ /**

module.exports.iframeToSlotName = function (iframeWindow) {
exports.getTimestamp = getTimestamp;
const iframeToSlotName = function iframeToSlotName(iframeWindow) {
// capture all iframes in the page in a live node list

@@ -465,3 +535,5 @@ const iframes = document.getElementsByTagName('iframe');

module.exports.buildObjectFromArray = function buildObjectFromArray(targetObject) {
exports.iframeToSlotName = iframeToSlotName;
const buildObjectFromArray = function buildObjectFromArray(targetObject) {
return targetObject.reduce((prev, data) => {

@@ -473,13 +545,46 @@ prev[data.key] = data.value;

module.exports.cookie = function (name) {
const val = document.cookie.match(`(^|;)\\s*${name}\\s*=\\s*([^;]+)`);
exports.buildObjectFromArray = buildObjectFromArray;
const cookie = function cookie(name) {
const val = document.cookie.match("(^|;)\\s*".concat(name, "\\s*=\\s*([^;]+)"));
return val ? val.pop() : null;
};
module.exports.getVersion = () => require("../version.js") || 'UNKNOWN';
exports.cookie = cookie;
extend(module.exports, require("./events.js"));
extend(module.exports, require("./messenger.js"));
module.exports.responsive = require("./responsive.js");
module.exports.log = require("./log");
curryIsMethods(module.exports);
const getVersion = () => _version.default || 'UNKNOWN';
exports.getVersion = getVersion;
var _default = {
on: _events.on,
off: _events.off,
once: _events.once,
broadcast: _events.broadcast,
messenger: _messenger.default,
responsive: _responsive.default,
log: _log.default,
isArray,
isString,
isFunction,
isStorage,
isObject,
isWindow,
isPlainObject,
isNonEmptyString,
isElement,
extend,
hash,
attach,
getReferrer,
dehyphenise,
parseAttributeName,
getLocation,
getQueryString,
getQueryParamByName,
getTimestamp,
iframeToSlotName,
buildObjectFromArray,
cookie,
getVersion
};
exports.default = _default;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = log;
exports.attributeTable = exports.table = exports.end = exports.start = exports.info = exports.error = exports.warn = exports.isOn = void 0;
var _index = require("./index");
/* eslint no-console: 0 */

@@ -13,3 +21,3 @@

/* jshint devel: true */
module.exports = log;
/**

@@ -21,3 +29,2 @@ * Safe logger for the browser

*/
function log() {

@@ -47,3 +54,3 @@ let type;

module.exports.isOn = function (type) {
const isOn = function isOn(type) {
/* istanbul ignore else */

@@ -58,3 +65,5 @@ const debug = localStorage && localStorage.getItem('oAds') || location.search.indexOf('DEBUG=OADS') !== -1;

module.exports.warn = function () {
exports.isOn = isOn;
const warn = function warn() {
const args = ['warn'].concat([].slice.call(arguments, 0));

@@ -68,3 +77,5 @@ log.apply(null, args);

module.exports.error = function () {
exports.warn = warn;
const error = function error() {
const args = ['error'].concat([].slice.call(arguments, 0));

@@ -78,3 +89,5 @@ log.apply(null, args);

module.exports.info = function () {
exports.error = error;
const info = function info() {
const args = ['info'].concat([].slice.call(arguments, 0));

@@ -89,3 +102,5 @@ log.apply(null, args);

module.exports.start = function (group) {
exports.info = info;
const start = function start(group) {
if (!log.isOn('groupCollapsed')) {

@@ -102,3 +117,5 @@ return;

module.exports.end = function () {
exports.start = start;
const end = function end() {
if (!log.isOn('groupEnd')) {

@@ -111,3 +128,5 @@ return;

module.exports.table = function (data, columns) {
exports.end = end;
const table = function table(data, columns) {
if (log.isOn('log') && window.console) {

@@ -122,5 +141,5 @@ if (console.table) {

module.exports.attributeTable = function (object, columns) {
const utils = require("../utils");
exports.table = table;
const attributeTable = function attributeTable(object, columns) {
if (log.isOn('log') && window.console) {

@@ -131,3 +150,3 @@ if (object && console.table) {

if (utils.isArray(object[item]) || utils.isObject(object[item])) {
if ((0, _index.isArray)(object[item]) || (0, _index.isObject)(object[item])) {
val = JSON.stringify(object[item]);

@@ -148,2 +167,4 @@ } else {

}
};
};
exports.attributeTable = attributeTable;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
/**

@@ -8,3 +13,3 @@ * Utility methods for postMessage api.

*/
module.exports.messenger = {
var _default = {
post: function post(message, source) {

@@ -29,2 +34,4 @@ message = typeof message === 'string' ? message : JSON.stringify(message);

}
};
};
exports.default = _default;
module.exports = exports.default;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getCurrent = getCurrent;
exports.default = init;
exports.setThrottleInterval = void 0;
var _index = _interopRequireDefault(require("./index"));
var _oViewport = _interopRequireDefault(require("@financial-times/o-viewport"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
let callback;

@@ -7,10 +20,7 @@ let breakpoints;

const utils = require("./index.js");
const oViewport = require("@financial-times/o-viewport");
function getNearestBreakpoint() {
let winner;
const dims = oViewport.getSize(true);
const dims = _oViewport.default.getSize(true);
function findCurrentBreakpoint(breakpoint) {

@@ -48,3 +58,3 @@ const breakpointDims = breakpoints[breakpoint];

function init(brps, cb) {
if (!utils.isFunction(cb)) {
if (!_index.default.isFunction(cb)) {
// must have a call back function

@@ -59,9 +69,11 @@ return false;

document.body.addEventListener('oViewport.resize', fire);
oViewport.listenTo('orientation');
oViewport.listenTo('resize');
_oViewport.default.listenTo('orientation');
_oViewport.default.listenTo('resize');
return getCurrent();
}
module.exports = init;
module.exports.getCurrent = getCurrent;
module.exports.setThrottleInterval = oViewport.setThrottleInterval;
const setThrottleInterval = _oViewport.default.setThrottleInterval;
exports.setThrottleInterval = setThrottleInterval;

@@ -26,3 +26,3 @@ {

"name": "@financial-times/o-ads",
"version": "10.5.0",
"version": "11.0.0",
"dependencies": {

@@ -78,3 +78,3 @@ "dom-delegate": "^2.0.3",

"nightwatch": "^0.9.21",
"origami-build-tools": "^7.13.3",
"origami-build-tools": "^8.0.0",
"pre-git": "^3.17.1",

@@ -81,0 +81,0 @@ "qunitjs": "^1.20.0",

@@ -57,1 +57,6 @@ # oAds [![CircleCI Status](https://circleci.com/gh/Financial-Times/o-ads.svg?style=shield&circle-token=36a37c6ca27a08408c2575c7834f5f6f5c5c9d21)](https://circleci.com/gh/Financial-Times/o-ads/tree/master)

### Upgrading to v11
As of version 11, o-ads has been updated to use ES modules. Unfortunately, this means it is not backwards compatible with CJS modules and clients cannot `require('o-ads')` anymore.
- Breaking change: if importing o-ads in your build, you must now do it as follows: `import oAds from 'o-ads'`
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