Build dependencies tree of any artifacts with just single interfaces to implement

Usage no npm install needed!

<script type="module">
  import anyDependencyTree from '';



CircleCIGreenkeeper badge

Build and visualize dependency tree for any hierarchical structure.
Just implement element => dependencies: element[] interface


Install the package

npm i any-depepndency-tree


Implement EntityDependencyApi

const myImp: EntityDependencyApi<MyHierarchyType> = ...; // Mandatory custom implementation

Define 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 tree


Can visualize the tree using standard JSON.stringify approach

const serializingVisitor: = new SerializingVisitor();
const treeString: string = serializingVisitor.visitTree(rootNode);

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);

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);

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.


  1. index.test.ts
  2. serializing.test.ts
  3. ordering.test.ts


If you are interested in contributing, please take a look at the CONTRIBUTING guide.