(node)
| 109 | * @return {string} |
| 110 | */ |
| 111 | export 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 |
no test coverage detected