cleanview
Version:
Clean the content of html articles
33 lines (32 loc) • 936 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const helpers_1 = require("./helpers");
function query(tag, element) {
const founds = [];
search(tag, element, founds);
return founds;
}
function search(tag, element, founds) {
if (Array.isArray(element)) {
element.forEach(function (el) {
search(tag, el, founds);
});
return;
}
if (!(0, helpers_1.isNode)(element))
return;
// If the tagname match, add the element and return
if (element.tagName === tag) {
founds.push(element);
return;
}
// If the element doesn't have children there's no need to continue
if (!element.children)
return;
// If the element has children search recursively
element.children.forEach(function (el) {
if ((0, helpers_1.isNode)(el))
search(tag, el, founds);
});
}
exports.default = query;