# merge-stream

> Create a stream that emits events from multiple other streams

Latest version **2.0.0** (published 2019-05-23) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2.0.0 |
| Published | 2019-05-23 |
| First published | 2013-06-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/merge-stream) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 212 |
| Author | Stephen Sugden |
| Maintainers | grncdr, shinnn, stevemao |

## Links

- npm: https://www.npmjs.com/package/merge-stream
- Repository: https://github.com/grncdr/merge-stream
- Homepage: https://github.com/grncdr/merge-stream#readme
- Issues: https://github.com/grncdr/merge-stream/issues
- npm.io page: https://npm.io/package/merge-stream

## Recent versions

- 2.0.0 (latest) — 2019-05-23
- 1.0.1 — 2016-11-25
- 1.0.0 — 2015-08-10
- 0.1.8 — 2015-06-30
- 0.1.7 — 2015-01-10
- 0.1.6 — 2014-09-24
- 0.1.5 — 2014-07-06
- 0.1.4 — 2014-07-06
- 0.1.3 — 2014-07-06
- 0.1.2 — 2014-06-26
- 0.1.1 — 2014-05-20
- 0.0.1 — 2014-05-19
- 0.0.0 — 2013-06-10

## README

# merge-stream

Merge (interleave) a bunch of streams.

[![build status](https://secure.travis-ci.org/grncdr/merge-stream.svg?branch=master)](http://travis-ci.org/grncdr/merge-stream)

## Synopsis

```javascript
var stream1 = new Stream();
var stream2 = new Stream();

var merged = mergeStream(stream1, stream2);

var stream3 = new Stream();
merged.add(stream3);
merged.isEmpty();
//=> false
```

## Description

This is adapted from [event-stream](https://github.com/dominictarr/event-stream) separated into a new module, using Streams3.

## API

### `mergeStream`

Type: `function`

Merges an arbitrary number of streams. Returns a merged stream.

#### `merged.add`

A method to dynamically add more sources to the stream. The argument supplied to `add` can be either a source or an array of sources.

#### `merged.isEmpty`

A method that tells you if the merged stream is empty.

When a stream is "empty" (aka. no sources were added), it could not be returned to a gulp task.

So, we could do something like this:

```js
stream = require('merge-stream')();
// Something like a loop to add some streams to the merge stream
// stream.add(streamA);
// stream.add(streamB);
return stream.isEmpty() ? null : stream;
```

## Gulp example

An example use case for **merge-stream** is to combine parts of a task in a project's **gulpfile.js** like this:

```js
const gulp =          require('gulp');
const htmlValidator = require('gulp-w3c-html-validator');
const jsHint =        require('gulp-jshint');
const mergeStream =   require('merge-stream');

function lint() {
  return mergeStream(
    gulp.src('src/*.html')
      .pipe(htmlValidator())
      .pipe(htmlValidator.reporter()),
    gulp.src('src/*.js')
      .pipe(jsHint())
      .pipe(jsHint.reporter())
  );
}
gulp.task('lint', lint);
```

## License

MIT

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