forked from jaredly/treed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify-nodes.js
29 lines (26 loc) · 1006 Bytes
/
verify-nodes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module.exports = verifyNodes
function verifyNodes(root, map) {
if (!map[root]) return new Error("Root node not found")
return verifyNode(map[root], map)
}
function verifyNode(node, map) {
if (node.children) {
for (var i=0; i<node.children.length; i++) {
var child = map[node.children[i]]
if (!child) {
child = map[node.children[i]] = {id: node.children[i], content: '*contents missing*', parent: node.id, children: []}
console.log("Child node not found: " + node.children[i] + ' of ' + node.id)
// return new Error("Child node not found: " + node.children[i] + ' of ' + node.id)
}
if (child.parent !== node.id) {
console.log('Misparent')
console.log(node)
console.log(child)
child.parent = node.id
// return new Error("Misparented. " + child.id + " should have parent " + node.id + " but instead it is " + child.parent)
}
var err = verifyNode(child, map)
if (err) return err
}
}
}