MCPcopy Create free account
hub / github.com/ampproject/amphtml / getMultiSizeDimensions

Function getMultiSizeDimensions

ads/google/utils.js:41–143  ·  view source on GitHub ↗
(
  multiSizeDataStr,
  primaryWidth,
  primaryHeight,
  multiSizeValidation,
  isFluidPrimary = false
)

Source from the content-addressed store, hash-verified

39 * @return {?Array<!Array<number>>} An array of dimensions.
40 */
41export function getMultiSizeDimensions(
42 multiSizeDataStr,
43 primaryWidth,
44 primaryHeight,
45 multiSizeValidation,
46 isFluidPrimary = false
47) {
48 const dimensions = [];
49 const arrayOfSizeStrs = multiSizeDataStr.split(',');
50
51 for (let i = 0; i < arrayOfSizeStrs.length; i++) {
52 const sizeStr = arrayOfSizeStrs[i];
53 if (sizeStr.toLowerCase() == 'fluid') {
54 // Fluid dummy sizes should be appended to the front of the request
55 // parameter, so they must be handled elsewhere.
56 continue;
57 }
58 const size = sizeStr.split('x');
59
60 // Make sure that each size is specified in the form WxH.
61 if (size.length != 2) {
62 user().error('AMP-AD', `Invalid multi-size data format '${sizeStr}'.`);
63 continue;
64 }
65
66 const width = Number(size[0]);
67 const height = Number(size[1]);
68
69 // Make sure that both dimensions given are positive numbers.
70 if (
71 !validateDimensions(
72 width,
73 height,
74 (w) => isNaN(w) || w <= 0,
75 (h) => isNaN(h) || h <= 0,
76 (badParams) =>
77 badParams
78 .map(
79 (badParam) =>
80 `Invalid ${badParam.dim} of ${badParam.val} ` +
81 'given for secondary size.'
82 )
83 .join(' ')
84 )
85 ) {
86 continue;
87 }
88
89 // Check that secondary size is not larger than primary size.
90 if (
91 !isFluidPrimary &&
92 !validateDimensions(
93 width,
94 height,
95 (w) => w > primaryWidth,
96 (h) => h > primaryHeight,
97 (badParams) =>
98 badParams

Callers 4

test-utils.jsFile · 0.90
yieldbotFunction · 0.90
sasFunction · 0.90
getParameterSize_Method · 0.90

Calls 4

userFunction · 0.90
validateDimensionsFunction · 0.85
errorMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected