# topsort-stream

> Topological sort for streams

Latest version **0.2.0** (published 2015-09-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install topsort-stream
pnpm add topsort-stream
yarn add topsort-stream
bun add topsort-stream
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2015-09-04 |
| First published | 2015-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Peter Hancock |
| Maintainers | pjfh |

## Links

- npm: https://www.npmjs.com/package/topsort-stream
- Repository: https://github.com/PeterHancock/topsort-stream
- Issues: https://github.com/PeterHancock/topsort-stream/issues
- npm.io page: https://npm.io/package/topsort-stream

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) 3.8.0
- [through](https://npm.io/package/through.md) 2.3.6
- [es6-promise](https://npm.io/package/es6-promise.md) 2.1.1
- [es6-denodeify](https://npm.io/package/es6-denodeify.md) 0.1.4

## Recent versions

- 0.2.0 (latest) — 2015-09-04
- 0.1.4 — 2015-09-04
- 0.1.3 — 2015-05-15
- 0.1.2 — 2015-05-15
- 0.1.1 — 2015-03-09
- 0.1.0 — 2015-03-05

## README

#topsort-stream ![Travis CI status](https://api.travis-ci.org/PeterHancock/topsort-stream.png)


Topological sort for streams

[![NPM](https://nodei.co/npm/topsort-stream.png)](https://nodei.co/npm/topsort-stream/)

## Example

``` javascript
var topsort = require('topsort-stream')

var dependencies = {
    c: ['b'],
    d: ['b', 'c']
}

var s = new require('stream').Readable({ objectMode: true })

s.pipe(topsort(function (data) {
     return {
         id: data,
         deps: dependencies[data] || []
     }
 }))
 .on('data', console.log.bind(console))

s.push('d')
s.push('c')
s.push('a')
s.push('b')
s.push(null)
```

Yields
```
a
b
c
d
```

*'a'* and *'b'* where written to the destination stream after being read as they had no dependencies; *'a'* first because it was read before *'b'*. *'c'* and *'d'*  depended on *'b'* and written after; *'d'* was written last becauese it dependend upon *'c'*.  

A *real world* example would be a `gulp` plugin that is passed a `nodeResolver` (see **methods**) that extracts the dependencies from metadata from the file content.  

## API


``` javascript
var topsort = require('topsort-stream')
```
### methods

#### `var t = topsort(function nodeResolver(data) { return { [id: Object,] [deps: Array] } })`
 * `nodeResolver` defines the dependency graph bit assigning identity and dependencies to data.


## events

`t` inherits all all events from `stream.Readable`.

#### `t.on('topsort-error:resolving-node', cb)`

The event fires when there is an error resolving a node.


#### `t.on('topsort-error:unresolved-nodes', cb)`

The event fires when the readable side of the stream is closed before all dependencies have been resolved.  The call back is fired with an array of the ids of dependant nodes.

## Install

```
npm install topsort-stream
```

## license
MIT

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