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

Function createParseAttrsWithPrefix

src/preact/parse-props.js:360–392  ·  view source on GitHub ↗
(prefix)

Source from the content-addressed store, hash-verified

358 * }}
359 */
360export function createParseAttrsWithPrefix(prefix) {
361 /**
362 * @param {string} name
363 * @return {boolean}
364 */
365 const attrMatches = (name) => name?.startsWith(prefix) && name !== prefix;
366
367 /**
368 * @param {Element} element
369 * @return {JsonObject|undefined}
370 */
371 const parseAttrs = (element) => {
372 /** @type {JsonObject|undefined} */
373 let currObj = undefined;
374 const attrs = element.attributes;
375 for (let i = 0; i < attrs.length; i++) {
376 const attrib = attrs[i];
377 if (attrMatches(attrib.name)) {
378 if (!currObj) {
379 currObj = {};
380 }
381 currObj[dashToCamelCase(attrib.name.slice(prefix.length))] =
382 attrib.value;
383 }
384 }
385 return currObj;
386 };
387
388 return {
389 'attrMatches': attrMatches,
390 'parseAttrs': parseAttrs,
391 };
392}

Callers 6

base-element.jsFile · 0.90
base-element.jsFile · 0.90
base-element.jsFile · 0.90
base-element.jsFile · 0.90
base-element.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected