1.0.6 • Published 8 years ago
dependency-solver v1.0.6
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 } = require('dependency-solver');
var graph = {
'A': ['B', 'C', 'F'],
'B': ['C', 'D'],
'F': ['E'],
'C': ['D', 'E']
}
solve(graph);
// -> [ '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 } = require('dependency-solver');
getDependedBy(graph);
// -> { 'B': 1,
// 'A': 0,
// 'C': 2,
// 'F': 1,
// 'D': 2,
// 'E': 2 }
getDependencyLines(graph);
// -> [ [ '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