README.md (1813B)
1 # merge-stream 2 3 Merge (interleave) a bunch of streams. 4 5 [](http://travis-ci.org/grncdr/merge-stream) 6 7 ## Synopsis 8 9 ```javascript 10 var stream1 = new Stream(); 11 var stream2 = new Stream(); 12 13 var merged = mergeStream(stream1, stream2); 14 15 var stream3 = new Stream(); 16 merged.add(stream3); 17 merged.isEmpty(); 18 //=> false 19 ``` 20 21 ## Description 22 23 This is adapted from [event-stream](https://github.com/dominictarr/event-stream) separated into a new module, using Streams3. 24 25 ## API 26 27 ### `mergeStream` 28 29 Type: `function` 30 31 Merges an arbitrary number of streams. Returns a merged stream. 32 33 #### `merged.add` 34 35 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. 36 37 #### `merged.isEmpty` 38 39 A method that tells you if the merged stream is empty. 40 41 When a stream is "empty" (aka. no sources were added), it could not be returned to a gulp task. 42 43 So, we could do something like this: 44 45 ```js 46 stream = require('merge-stream')(); 47 // Something like a loop to add some streams to the merge stream 48 // stream.add(streamA); 49 // stream.add(streamB); 50 return stream.isEmpty() ? null : stream; 51 ``` 52 53 ## Gulp example 54 55 An example use case for **merge-stream** is to combine parts of a task in a project's **gulpfile.js** like this: 56 57 ```js 58 const gulp = require('gulp'); 59 const htmlValidator = require('gulp-w3c-html-validator'); 60 const jsHint = require('gulp-jshint'); 61 const mergeStream = require('merge-stream'); 62 63 function 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 } 73 gulp.task('lint', lint); 74 ``` 75 76 ## License 77 78 MIT