UNPKG

x

Version:

Apply HTML transformations using attributes

44 lines (36 loc) 719 B
'use strict' const parse5 = require('parse5') const vinyl = require('vinyl') function normalize (path) { return path.replace(/[\\\/]+/g, '/') } function * walkNodes (node) { if (node.childNodes) { yield * walkNodesUnchecked(node) } } function * walkNodesUnchecked (node) { for (let child of node.childNodes) { yield child if (child.childNodes) { yield * walkNodesUnchecked(child) } } } function getRootNode (node) { while (node.parentNode) { node = node.parentNode } return node } function isExternal (ref) { return /^(?:[a-zA-Z][a-zA-Z0-9+.-]*:(?:\/\/)?|\/\/)/.test(ref) } module.exports = { parse5, vinyl, normalize, walkNodes, getRootNode, isExternal }