MCPcopy
hub / github.com/ampproject/amphtml / parseSrcset

Function parseSrcset

src/core/dom/srcset.js:57–79  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

55 * @return {Srcset<SrcsetSourceDef>}
56 */
57export function parseSrcset(s) {
58 const sources = [];
59 let match;
60 while ((match = srcsetRegex.exec(s))) {
61 const url = match[1];
62 let width, dpr;
63 if (match[2]) {
64 const type = match[3].toLowerCase();
65 if (type == 'w') {
66 width = parseInt(match[2], 10);
67 } else if (type == 'x') {
68 dpr = parseFloat(match[2]);
69 } else {
70 continue;
71 }
72 } else {
73 // If no "w" or "x" specified, we assume it's "1x".
74 dpr = 1;
75 }
76 sources.push(/** @type {SrcsetSourceDef} */ ({url, width, dpr}));
77 }
78 return new Srcset(sources);
79}
80
81/**
82 * A srcset object contains one or more sources.

Callers 6

testFunction · 0.90
test-srcset.jsFile · 0.90
resolveUrlAttrFunction · 0.90
isResultValidMethod · 0.90
srcsetFromElementFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by 1

testFunction · 0.72