Dependency Solver
A tiny dependency solver using topological sorting. Returns a list of nodes where no node comes before it's dependencies.
Usage
Nodes can be in any order. Any valid property name is a valid node. Circular dependencies throw an error.
var solve = ; var graph = 'A': 'B' 'C' 'F' 'B': 'C' 'D' 'F': 'E' 'C': 'D' 'E' ;// -> [ 'D', 'E', 'C', 'B', 'F', 'A' ]
You can also compute how many nodes depend on a particular node and dependency lines between nodes.
var getDependedBy getDependencyLines = ; ;// -> { 'B': 1, // 'A': 0, // 'C': 2, // 'F': 1, // 'D': 2, // 'E': 2 } ;// -> [ [ 'A', 'B' ],// [ 'A', 'C' ],// [ 'A', 'F' ],// [ 'B', 'C' ],// [ 'B', 'D' ],// [ 'F', 'E' ],// [ 'C', 'D' ],// [ 'C', 'E' ] ]
License
This project is licensed under the MIT License - see the LICENSE.md file for details