UNPKG

uhtml

Version:
25 lines (19 loc) • 636 B
'use strict'; const { DOCUMENT_FRAGMENT_NODE } = require('domconstants/constants'); const { nodeType, childNodes } = require('./symbols.js'); const push = (array, nodes) => { array.push(...nodes.flatMap(withoutFragments)); }; exports.push = push; const splice = (array, start, drop, nodes) => { array.splice(start, drop, ...nodes.flatMap(withoutFragments)); }; exports.splice = splice; const unshift = (array, nodes) => { array.unshift(...nodes.flatMap(withoutFragments)); }; exports.unshift = unshift; const withoutFragments = node => ( node[nodeType] === DOCUMENT_FRAGMENT_NODE ? node[childNodes].splice(0) : node );