@rx-now/analysis
Version:
analysis tool for visualizing for code dependencies in typescript
23 lines (22 loc) • 721 B
JavaScript
export function appendPath(tree, items, equals = (a, b) => a === b) {
let curr = tree;
items.forEach((item) => {
var _a;
let next = (_a = curr.children) === null || _a === void 0 ? void 0 : _a.find((c) => equals(c.node, item));
if (!next) {
if (!curr.children) {
curr.children = [];
}
next = { node: item, count: 0, children: [] };
curr.children.push(next);
}
curr = next;
});
curr.count += 1;
return tree;
}
export function dfs(tree, func, ext) {
var _a;
const data = func(tree, ext);
(_a = tree.children) === null || _a === void 0 ? void 0 : _a.forEach((c) => dfs(c, func, data));
}