UNPKG

@test-runner/web

Version:
26 lines (24 loc) 687 B
/** * @param {string} html * @param {object} [options] * @param {object} [options.document] * @param {string} [options.parentEl] */ function domify (html, options) { options = Object.assign({}, { document: typeof document === 'undefined' ? undefined : document, parentEl: 'container' }, options) const div = options.document.createElement(options.parentEl) div.innerHTML = html.trim() if (div.childNodes.length === 1) { return div.firstChild } else { const frag = options.document.createDocumentFragment() Array.from(div.childNodes).forEach(function (childNode) { frag.appendChild(childNode) }) return frag } } export default domify