| 606 | * the new tree to find the node that matches the path |
| 607 | */ |
| 608 | export function findInTree(rootNode, path) { |
| 609 | if (path === null) { |
| 610 | return rootNode; |
| 611 | } |
| 612 | return (function findInNode(currentNode) { |
| 613 | |
| 614 | /* No point in checking the children if |
| 615 | * the path for currentNode itself is not matching |
| 616 | */ |
| 617 | if (currentNode.path !== undefined && path !== undefined |
| 618 | && !path.startsWith(currentNode.path)) { |
| 619 | return null; |
| 620 | } |
| 621 | |
| 622 | for (let i = 0, length = currentNode.children.length; i < length; i++) { |
| 623 | const calculatedNode = findInNode(currentNode.children[i]); |
| 624 | if (calculatedNode !== null) { |
| 625 | return calculatedNode; |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | if (currentNode.path === path) { |
| 630 | return currentNode; |
| 631 | } else { |
| 632 | return null; |
| 633 | } |
| 634 | })(rootNode); |
| 635 | } |
| 636 | |
| 637 | const isValidTreeNodeData = (data) => (!_.isEmpty(data)); |
| 638 | |