forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from prebid/master
merge master
- Loading branch information
Showing
138 changed files
with
1,374 additions
and
894 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Converts a string value in camel-case to underscore eg 'placementId' becomes 'placement_id' | ||
* @param {string} value string value to convert | ||
*/ | ||
import {deepClone, isPlainObject} from '../../src/utils.js'; | ||
|
||
export function convertCamelToUnderscore(value) { | ||
return value.replace(/(?:^|\.?)([A-Z])/g, function (x, y) { | ||
return '_' + y.toLowerCase(); | ||
}).replace(/^_/, ''); | ||
} | ||
|
||
/** | ||
* Creates an array of n length and fills each item with the given value | ||
*/ | ||
export function fill(value, length) { | ||
let newArray = []; | ||
|
||
for (let i = 0; i < length; i++) { | ||
let valueToPush = isPlainObject(value) ? deepClone(value) : value; | ||
newArray.push(valueToPush); | ||
} | ||
|
||
return newArray; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* http://npm.im/chunk | ||
* Returns an array with *size* chunks from given array | ||
* | ||
* Example: | ||
* ['a', 'b', 'c', 'd', 'e'] chunked by 2 => | ||
* [['a', 'b'], ['c', 'd'], ['e']] | ||
*/ | ||
export function chunk(array, size) { | ||
let newArray = []; | ||
|
||
for (let i = 0; i < Math.ceil(array.length / size); i++) { | ||
let start = i * size; | ||
let end = start + size; | ||
newArray.push(array.slice(start, end)); | ||
} | ||
|
||
return newArray; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {find} from '../../src/polyfill.js'; | ||
import {compareCodeAndSlot, isGptPubadsDefined} from '../../src/utils.js'; | ||
|
||
/** | ||
* Returns filter function to match adUnitCode in slot | ||
* @param {string} adUnitCode AdUnit code | ||
* @return {function} filter function | ||
*/ | ||
export function isSlotMatchingAdUnitCode(adUnitCode) { | ||
return (slot) => compareCodeAndSlot(slot, adUnitCode); | ||
} | ||
|
||
/** | ||
* @summary Uses the adUnit's code in order to find a matching gpt slot object on the page | ||
*/ | ||
export function getGptSlotForAdUnitCode(adUnitCode) { | ||
let matchingSlot; | ||
if (isGptPubadsDefined()) { | ||
// find the first matching gpt slot on the page | ||
matchingSlot = find(window.googletag.pubads().getSlots(), isSlotMatchingAdUnitCode(adUnitCode)); | ||
} | ||
return matchingSlot; | ||
} | ||
|
||
/** | ||
* @summary Uses the adUnit's code in order to find a matching gptSlot on the page | ||
*/ | ||
export function getGptSlotInfoForAdUnitCode(adUnitCode) { | ||
const matchingSlot = getGptSlotForAdUnitCode(adUnitCode); | ||
if (matchingSlot) { | ||
return { | ||
gptSlot: matchingSlot.getAdUnitPath(), | ||
divId: matchingSlot.getSlotElementId() | ||
}; | ||
} | ||
return {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Encode a string for inclusion in HTML. | ||
* See https://pragmaticwebsecurity.com/articles/spasecurity/json-stringify-xss.html and | ||
* https://codeql.github.com/codeql-query-help/javascript/js-bad-code-sanitization/ | ||
* @return {string} | ||
*/ | ||
export const escapeUnsafeChars = (() => { | ||
const escapes = { | ||
'<': '\\u003C', | ||
'>': '\\u003E', | ||
'/': '\\u002F', | ||
'\\': '\\\\', | ||
'\b': '\\b', | ||
'\f': '\\f', | ||
'\n': '\\n', | ||
'\r': '\\r', | ||
'\t': '\\t', | ||
'\0': '\\0', | ||
'\u2028': '\\u2028', | ||
'\u2029': '\\u2029' | ||
}; | ||
|
||
return function (str) { | ||
return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g, x => escapes[x]); | ||
}; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Read an adUnit object and return the sizes used in an [[728, 90]] format (even if they had [728, 90] defined) | ||
* Preference is given to the `adUnit.mediaTypes.banner.sizes` object over the `adUnit.sizes` | ||
* @param {object} adUnit one adUnit object from the normal list of adUnits | ||
* @returns {Array.<number[]>} array of arrays containing numeric sizes | ||
*/ | ||
export function getAdUnitSizes(adUnit) { | ||
if (!adUnit) { | ||
return; | ||
} | ||
|
||
let sizes = []; | ||
if (adUnit.mediaTypes && adUnit.mediaTypes.banner && Array.isArray(adUnit.mediaTypes.banner.sizes)) { | ||
let bannerSizes = adUnit.mediaTypes.banner.sizes; | ||
if (Array.isArray(bannerSizes[0])) { | ||
sizes = bannerSizes; | ||
} else { | ||
sizes.push(bannerSizes); | ||
} | ||
// TODO - remove this else block when we're ready to deprecate adUnit.sizes for bidders | ||
} else if (Array.isArray(adUnit.sizes)) { | ||
if (Array.isArray(adUnit.sizes[0])) { | ||
sizes = adUnit.sizes; | ||
} else { | ||
sizes.push(adUnit.sizes); | ||
} | ||
} | ||
return sizes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {isFn} from '../../src/utils.js'; | ||
|
||
/** | ||
* Try to convert a value to a type. | ||
* If it can't be done, the value will be returned. | ||
* | ||
* @param {string} typeToConvert The target type. e.g. "string", "number", etc. | ||
* @param {*} value The value to be converted into typeToConvert. | ||
*/ | ||
function tryConvertType(typeToConvert, value) { | ||
if (typeToConvert === 'string') { | ||
return value && value.toString(); | ||
} else if (typeToConvert === 'number') { | ||
return Number(value); | ||
} else { | ||
return value; | ||
} | ||
} | ||
|
||
export function convertTypes(types, params) { | ||
Object.keys(types).forEach(key => { | ||
if (params[key]) { | ||
if (isFn(types[key])) { | ||
params[key] = types[key](params[key]); | ||
} else { | ||
params[key] = tryConvertType(types[key], params[key]); | ||
} | ||
|
||
// don't send invalid values | ||
if (isNaN(params[key])) { | ||
delete params.key; | ||
} | ||
} | ||
}); | ||
return params; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function tryAppendQueryString(existingUrl, key, value) { | ||
if (value) { | ||
return existingUrl + key + '=' + encodeURIComponent(value) + '&'; | ||
} | ||
|
||
return existingUrl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.