basant307/AI_Governance_Project
045
1# merge-stream2 3Merge (interleave) a bunch of streams.4 5[](http://travis-ci.org/grncdr/merge-stream)6 7## Synopsis8 9```javascript10var stream1 = new Stream();11var stream2 = new Stream();12 13var merged = mergeStream(stream1, stream2);14 15var stream3 = new Stream();16merged.add(stream3);17merged.isEmpty();18//=> false19```20 21## Description22 23This is adapted from [event-stream](https://github.com/dominictarr/event-stream) separated into a new module, using Streams3.24 25## API26 27### `mergeStream`28 29Type: `function`30 31Merges an arbitrary number of streams. Returns a merged stream.32 33#### `merged.add`34 35A method to dynamically add more sources to the stream. The argument supplied to `add` can be either a source or an array of sources.36 37#### `merged.isEmpty`38 39A method that tells you if the merged stream is empty.40 41When a stream is "empty" (aka. no sources were added), it could not be returned to a gulp task.42 43So, we could do something like this:44 45```js46stream = require('merge-stream')();47// Something like a loop to add some streams to the merge stream48// stream.add(streamA);49// stream.add(streamB);50return stream.isEmpty() ? null : stream;51```52 53## Gulp example54 55An example use case for **merge-stream** is to combine parts of a task in a project's **gulpfile.js** like this:56 57```js58const gulp = require('gulp');59const htmlValidator = require('gulp-w3c-html-validator');60const jsHint = require('gulp-jshint');61const mergeStream = require('merge-stream');62 63function lint() {64 return mergeStream(65 gulp.src('src/*.html')66 .pipe(htmlValidator())67 .pipe(htmlValidator.reporter()),68 gulp.src('src/*.js')69 .pipe(jsHint())70 .pipe(jsHint.reporter())71 );72}73gulp.task('lint', lint);74```75 76## License77 78MIT79 