# sorted-union-stream

> Get the union of two sorted streams

Latest version **3.2.3** (published 2023-03-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install sorted-union-stream
pnpm add sorted-union-stream
yarn add sorted-union-stream
bun add sorted-union-stream
```

## 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 | 3.2.3 |
| Published | 2023-03-09 |
| First published | 2013-09-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Author | Mathias Buus Madsen |
| Maintainers | mafintosh |
| Keywords | union, sorted, stream |

## Links

- npm: https://www.npmjs.com/package/sorted-union-stream
- Repository: https://github.com/mafintosh/sorted-union-stream
- Issues: https://github.com/mafintosh/sorted-union-stream/issues
- npm.io page: https://npm.io/package/sorted-union-stream

## Dependencies (1)

- [streamx](https://npm.io/package/streamx.md) ^2.6.0

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 3.2.3 (latest) — 2023-03-09
- 3.2.2 — 2023-03-02
- 3.2.1 — 2023-03-02
- 3.2.0 — 2023-03-02
- 3.1.0 — 2021-09-01
- 3.0.1 — 2020-01-15
- 3.0.0 — 2020-01-15
- 2.1.3 — 2015-06-16
- 2.1.2 — 2015-06-16
- 2.1.1 — 2015-04-08
- 2.1.0 — 2015-04-08
- 2.0.0 — 2015-04-02
- 1.0.2 — 2014-12-22
- 1.0.1 — 2014-09-18
- 1.0.0 — 2014-09-18
- … 7 more at https://npm.io/package/sorted-union-stream/versions

## README

# sorted-union-stream

Get the union of two sorted streams

```
npm install sorted-union-stream
```

[![build status](https://secure.travis-ci.org/mafintosh/sorted-union-stream.png)](http://travis-ci.org/mafintosh/sorted-union-stream)

## Usage

``` js
const union = require('sorted-union-stream')
const { Readable } = require('streamx')

// from converts an array into a stream
const sorted1 = Readable.from([1, 10, 24, 42, 43, 50, 55])
const sorted2 = Readable.from([10, 42, 53, 55, 60])

// combine the two streams into a single sorted stream
const u = new Union(sorted1, sorted2)

u.on('data', function(data) {
  console.log(data)
})
u.on('end', function() {
  console.log('no more data')
})
```

Running the above example will print

```
1
10
24
42
43
50
53
55
60
no more data
```

## Streaming objects

If you are streaming objects sorting is based on the compare function you can pass as the 3rd argument.

``` js
const sorted1 = Readable.from([{ foo:'a' }, { foo:'b' }, { foo:'c' }])
const sorted2 = Readable.from([{ foo:'b' }, { foo:'d' }])

const u = new Union(sorted1, sorted2, function(a, b) {
  return a.foo < b.foo ? -1 : a.foo > b.foo ? 1 : 0 
})

union.on('data', function(data) {
  console.log(data)
})
```

Running the above will print

``` js
{ foo: 'a' }
{ foo: 'b' }
{ foo: 'c' }
{ foo: 'd' }
```

## License

MIT

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