UNPKG

@1771technologies/lytenyte-pro

Version:

Blazingly fast headless React data grid with 100s of features.

19 lines (18 loc) 641 B
const invalidPathRoute = "Invalid path specified. Paths must be built up incrementally."; const invalidPathChild = "Invalid path specified. Leaf nodes can have children."; export function getParentNodeByPath(tree, path) { let target = tree; for (let i = 0; i < path.length; i++) { const next = target.byPath.get(path[i]); if (!next) { console.error(invalidPathRoute, path.slice(0, i)); return null; } if (next.kind === "leaf") { console.error(invalidPathChild, path.slice(0, i)); return null; } target = next; } return target; }