# dependency-solver

> A tiny dependency solver using topological sorting

Latest version **1.0.6** (published 2017-02-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install dependency-solver
pnpm add dependency-solver
yarn add dependency-solver
bun add dependency-solver
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2017-02-21 |
| First published | 2017-02-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/dependency-solver) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Elis Haavistu |
| Maintainers | haavistu |
| Keywords | dependency, denepdency-solver, dependency-parser, topological, topological-sort, kahn |

## Links

- npm: https://www.npmjs.com/package/dependency-solver
- Repository: https://github.com/haavistu/dependency-solver
- Homepage: https://github.com/haavistu/dependency-solver#readme
- Issues: https://github.com/haavistu/dependency-solver/issues
- npm.io page: https://npm.io/package/dependency-solver

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.0.6 (latest) — 2017-02-21
- 1.0.5 — 2017-02-21
- 1.0.4 — 2017-02-21
- 1.0.3 — 2017-02-20
- 1.0.2 — 2017-02-20
- 1.0.1 — 2017-02-20
- 1.0.0 — 2017-02-20

## README

# Dependency Solver

[![Build Status](https://travis-ci.org/haavistu/dependency-solver.svg?branch=master)](https://travis-ci.org/haavistu/dependency-solver)

A tiny dependency solver using topological sorting. Returns a list of nodes where no node comes before it's dependencies.  

![dep-solver](https://cloud.githubusercontent.com/assets/25879989/23125249/7cd12be6-f779-11e6-87c2-721baa84402d.png)

## Usage

Nodes can be in any order. Any valid property name is a valid node. Circular dependencies throw an error.

```javascript
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.

```javascript
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](LICENSE.md) file for details

---
_Source: https://npm.io/package/dependency-solver · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
