# dependency-tree-resolver

> An easy-to-use library to resolve dependencies in a dependency tree

Latest version **1.0.3** (published 2018-05-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install dependency-tree-resolver
pnpm add dependency-tree-resolver
yarn add dependency-tree-resolver
bun add dependency-tree-resolver
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-05-03 |
| First published | 2016-01-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Shai Lachmanovich |
| Maintainers | shaylh |

## Links

- npm: https://www.npmjs.com/package/dependency-tree-resolver
- Repository: https://github.com/shaylh/dependency-resolver
- Homepage: https://github.com/shaylh/dependency-resolver#readme
- Issues: hhttps://github.com/shaylh/dependency-resolver/issues
- npm.io page: https://npm.io/package/dependency-tree-resolver

## Recent versions

- 1.0.3 (latest) — 2018-05-03
- 1.0.2 — 2016-01-06
- 1.0.1 — 2016-01-04
- 1.0.0 — 2016-01-04

## README

# dependency-resolver
If you have a dependency tree, and you'd like to know in which order to initialize each node, this library is for you.

## How to use

### Node
In CLI, execute 
```
npm i dependency-tree-resolver --save-dev
```
and then 
```javascript
var DepResolver =  require('dependency-tree-resolver');
```

### Browser
Get a local copy of [dep-res.js](src/dep-res.js), or consume it via [RawGit's CDN](https://cdn.rawgit.com/shaylh/dependency-resolver/master/src/dep-res.js),
and add to your HTML:
```html
<script type="text/javascript" src="dep-res.js"></script>
```
and then you'll have ```DepResolver``` on the  ```window``` scope.

## API
Once you include the script in your project you'll have a function ```DepResolver``` which accepts two arguments:
```javascript
DepResolver(
    tree = {
        string: [...string],
        ...
    }, 
    options = {
        exclude: [...string]
    }
)
```
## Arguments
*  ```tree```: each key in the map represents a node in the tree, and each value in the array represents a single dependency of that node.
* ```options```:
    * ```exclude```: allows you to specify which dependencies are special and allowed to not have a node for themselves (usefull when depending on external resources)

## Examples
```javascript
//valid tree
var tree = {a: [], b: ['c', 'd'], c: ['d'], d: ['a']};
var resolved = DepResolver(tree);
console.log(resolved);//['a','d','c','b' ]

//invalid tree w/ excluded external resource
var tree = {a: ['b'], b: ['d']};
var options = {exclude: ['d']};
var resolved = DepResolver(tree, options);
console.log(resolved);//['b','a']

//invalid tree w/o excluded external resource
var tree = {a: ['b'], b: ['d']};
var resolved = DepResolver(tree);//throw error: "b" has an unknown dependency "d"

//invalid tree with cyclic dependency
var tree = {a: ['b'], b: ['c'], c: ['a'], d: ['e'], e: ['d']};
var resolved = DepResolver(tree);//throw error: circular dependency found: a > b > c > a
```
## License
This library is provided under the [MIT license](http://choosealicense.com/licenses/mit/).

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