syphonx-core
Version:
SyphonX is a template-driven solution for extracting data from HTML in a highly efficient way. It combines the power of jQuery, Regular Expressions, and Javascript into a declarative template-driven format that extracts and reshapes HTML data into JSON.
16 lines • 646 B
JavaScript
export function mergeElements(source, target) {
for (const targetAttr of Array.from(target[0].attributes)) {
const sourceAttr = Array.from(source[0].attributes).find(attr => attr.name === targetAttr.name);
if (sourceAttr && targetAttr.name === "class") {
const value = Array.from(new Set([
...sourceAttr.value.split(" "),
...targetAttr.value.split(" ")
])).join(" ");
source.attr("class", value);
}
else if (!sourceAttr) {
source.attr(targetAttr.name, targetAttr.value);
}
}
}
//# sourceMappingURL=mergeElements.js.map