dependency-solver
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/dependency-solver package

1.0.6 • Public • Published

Dependency Solver

Build Status

A tiny dependency solver using topological sorting. Returns a list of nodes where no node comes before it's dependencies.

dep-solver

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

Package Sidebar

Install

npm i dependency-solver

Weekly Downloads

627

Version

1.0.6

License

MIT

Last publish

Collaborators

  • haavistu