项目作者: haavistu

项目描述 :
A tiny dependency solver using topological sorting
高级语言: JavaScript
项目地址: git://github.com/haavistu/dependency-solver.git
创建时间: 2017-02-20T06:17:32Z
项目社区:https://github.com/haavistu/dependency-solver

开源协议:MIT License

下载


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.

  1. var { solve } = require('dependency-solver');
  2. var graph = {
  3. 'A': ['B', 'C', 'F'],
  4. 'B': ['C', 'D'],
  5. 'F': ['E'],
  6. 'C': ['D', 'E']
  7. }
  8. solve(graph);
  9. // -> [ 'D', 'E', 'C', 'B', 'F', 'A' ]

You can also compute how many nodes depend on a particular node and dependency lines between nodes.

  1. var { getDependedBy, getDependencyLines } = require('dependency-solver');
  2. getDependedBy(graph);
  3. // -> { 'B': 1,
  4. // 'A': 0,
  5. // 'C': 2,
  6. // 'F': 1,
  7. // 'D': 2,
  8. // 'E': 2 }
  9. getDependencyLines(graph);
  10. // -> [ [ 'A', 'B' ],
  11. // [ 'A', 'C' ],
  12. // [ 'A', 'F' ],
  13. // [ 'B', 'C' ],
  14. // [ 'B', 'D' ],
  15. // [ 'F', 'E' ],
  16. // [ 'C', 'D' ],
  17. // [ 'C', 'E' ] ]

License

This project is licensed under the MIT License - see the LICENSE.md file for details