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

Function parseEpoch

src/core/dom/parse-date-attributes.js:48–70  ·  view source on GitHub ↗

* Parse epoch from list of possible element attributes, returning the first one * that is truthy. * @param {Element} element * @param {Array } dateAttrs list of attribute names * @return {?TimestampDef}

(element, dateAttrs)

Source from the content-addressed store, hash-verified

46 * @return {?TimestampDef}
47 */
48function parseEpoch(element, dateAttrs) {
49 // Validate provided dateAttrs outside the loop so it will fail when an
50 // invalid attr is provided, even if that attribute isn't present on the
51 // element.
52 /** @type {Array<DateParserDef>} */
53 const parsers = dateAttrs.map((attrName) => {
54 devAssert(
55 dateAttrParsers[attrName],
56 'Invalid date attribute "%s"',
57 attrName
58 );
59 return dateAttrParsers[attrName];
60 });
61
62 for (let i = 0; i < dateAttrs.length; ++i) {
63 const attrVal = element.getAttribute(dateAttrs[i]);
64 if (attrVal) {
65 return parsers[i](attrVal);
66 }
67 }
68
69 return null;
70}

Callers 1

parseDateAttrsFunction · 0.85

Calls 2

devAssertFunction · 0.90
getAttributeMethod · 0.80

Tested by

no test coverage detected