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

Function getDeterministicOuterHTML

testing/helpers/index.js:111–129  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

109 * @return {string}
110 */
111export function getDeterministicOuterHTML(node) {
112 const tag = node.localName;
113 const attributes = Array.from(node.attributes)
114 .map(({name, value}) => `${name}="${value}"`)
115 .sort()
116 .join(' ');
117 const start = `<${tag} ${attributes}>`;
118 const contents = Array.from(node.childNodes).map((childNode) => {
119 if (childNode.nodeType === Node.ELEMENT_NODE) {
120 return getDeterministicOuterHTML(/** @type {Element} */ (childNode));
121 }
122 return childNode.textContent;
123 });
124
125 if (!contents && isVoidElement(node)) {
126 return start;
127 }
128 return start + contents + `</${tag}>`;
129}
130
131/**
132 * @param {string} hyphenCase camel cased string

Callers 5

test-builders.jsFile · 0.90
test-amp-layout.jsFile · 0.90

Calls 1

isVoidElementFunction · 0.85

Tested by

no test coverage detected