Skip to content
Permalink
Browse files
Simplify some helpers in util/xml-helpers (#40)
No functional changes. Just cleanup.
  • Loading branch information
raphinesse committed Aug 16, 2018
1 parent d3a8dee commit b296be547ae6e4afc1bfd7f9fd03f1e6be1f0ba9
Showing 1 changed file with 5 additions and 25 deletions.
@@ -137,8 +137,8 @@ module.exports = {
if (!parent) return false;

nodes.forEach(function (node) {
var matchingKid = null;
if ((matchingKid = findChild(node, parent)) !== null) {
var matchingKid = findChild(node, parent);
if (matchingKid !== undefined) {
// stupid elementtree takes an index argument it doesn't use
// and does not conform to the python lib
parent.remove(matchingKid);
@@ -208,32 +208,12 @@ module.exports = {
};

function findChild (node, parent) {
var matchingKids = parent.findall(node.tag);
var i;
var j;

for (i = 0, j = matchingKids.length; i < j; i++) {
if (module.exports.equalNodes(node, matchingKids[i])) {
return matchingKids[i];
}
}
return null;
const matches = parent.findall(node.tag);
return matches.find(m => module.exports.equalNodes(node, m));
}

function uniqueChild (node, parent) {
var matchingKids = parent.findall(node.tag);
var i = 0;

if (matchingKids.length === 0) {
return true;
} else {
for (i; i < matchingKids.length; i++) {
if (module.exports.equalNodes(node, matchingKids[i])) {
return false;
}
}
return true;
}
return !findChild(node, parent);
}

// Find the index at which to insert an entry. After is a ;-separated priority list

0 comments on commit b296be5

Please sign in to comment.