Repository URL to install this package:
|
Version:
1.4.3 ▾
|
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Checks if an object's type is undefined
*
* @param {*} obj - The object reference to be checked
* @return {boolean}
*/
var isUndefined = function isUndefined(obj) {
return typeof obj === 'undefined';
};
/**
* Helper to pluralize words in error messages
*
* @param {string} word - A string that will be suffixed with an 's' if collection has more than 1 member
* @param {Array} arr - The group of items
* @return {string} Either the word sufixed with a simple plural, 's', or the provided original
*/
var pluralize = function pluralize(word, arr) {
return arr.length > 1 ? "".concat(word, "s") : word;
};
/**
* Computes a flag based on given probability thresholds and a sampling rate
*
* @param {TrackingApiServices} services An HTML element to inspect
* @param {Number|Boolean} samplingRate A number from 0 to 1 (inclusive), or a boolean
* @return {TrackingApiServices}
*/
var sampleServices = function sampleServices(services, samplingRate) {
return Object.keys(services).reduce(function (acc, cur) {
var serviceThreshold = services[cur];
acc[cur] = serviceThreshold >= samplingRate;
return acc;
}, {});
};
/**
* Provides a basic polyfill for Promise.allSettled
*
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled
* @see https://caniuse.com/#feat=mdn-javascript_builtins_promise_allsettled
* @param {Promise[]} arr An array of Promises
* @return {Promise<Array<{status: string, value: any}|{status: string, reason: Error}>>}
*/
var allSettledPolyfill = function allSettledPolyfill(arr) {
return Promise.all(arr.map(function (promise) {
return promise.then(function (value) {
return {
status: 'fulfilled',
value: value
};
}).catch(function (error) {
return {
status: 'rejected',
reason: error
};
});
}));
};
exports.allSettledPolyfill = allSettledPolyfill;
exports.isUndefined = isUndefined;
exports.pluralize = pluralize;
exports.sampleServices = sampleServices;
//# sourceMappingURL=utils.js.map