any-dependency-tree
v2.2.0
Published
Build dependencies tree of any artifacts with just single interfaces to implement
Downloads
85
Readme
Description
Build and visualize dependency tree for any hierarchical structure.
Just implement element => dependencies: element[] interface
Usage
Install the package
npm i any-depepndency-treeMinimal
...
const myImp: EntityDependencyApi<MyHierarchyType> = ...; // Mandatory custom implementationDefine starting point of the tree
const myRoot: MyHierarchyType = ...; // this is starting poing of the tree;Build the complete tree
...
const builder = new DependencyTreeBuilder<MyHierarchyType>(myImp);
const rootNode = await dependencyTreeBuilder.buildDependencyTree(myRoot);
// now the rootTreeNode has the complete treeOptional
Can visualize the tree using standard JSON.stringify approach
...
const serializingVisitor: = new SerializingVisitor();
const treeString: string = serializingVisitor.visitTree(rootNode);
console.log(treeString);Or via custom implementation of tree node element visualizer
...
const customSerializer: Serializer<MyHierarchyType> = ... // Optional custom implementation
const serializingVisitor: = new SerializingVisitor(customSerializer);
const treeString: string = serializingVisitor.visitTree(rootTreeNode);
console.log(treeString);Also supports:
- Exclusion filter to remove sub-tree
- Inclusion filter to leave only some parts of the tree
...
const exclusionFilter: Filter<MyHierarchyType> = ... // Optional custom implementation
const inclusionFilter: Filter<MyHierarchyType> = ... // Optional custom implementation
const serializingVisitor: = new SerializingVisitor(customSerializer, inclusionFilter, exclusionFilter);
const filteredTreeString: string = serializingVisitor.visitTree(rootTreeNode);
console.log(filteredTreeString);Can also convert built tree into the ordered list where children are at the beginning
const orderVisitor: Ordering = new OrderingVisitor(true);
const orderedElements: DependencyTreeNode<any>[] = orderVisitor.visitTree(rootNode);orderedElements now contains all nodes from the tree including root as the very last element.
Examples
Contribution
If you are interested in contributing, please take a look at the CONTRIBUTING guide.
