merge-stream
Create a stream that emits events from multiple other streams
Last updated 2 months ago by stevemao .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install merge-stream 
SYNC missed versions from official npm registry.

merge-stream

Merge (interleave) a bunch of streams.

build status

Synopsis

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 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:

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:

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

Current Tags

  • 2.0.0                                ...           latest (2 months ago)

13 Versions

  • 2.0.0                                ...           2 months ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           4 years ago
  • 0.1.8                                ...           4 years ago
  • 0.1.7                                ...           5 years ago
  • 0.1.6                                ...           5 years ago
  • 0.1.5                                ...           5 years ago
  • 0.1.4                                ...           5 years ago
  • 0.1.3                                ...           5 years ago
  • 0.1.2                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.0.1                                ...           5 years ago
  • 0.0.0                                ...           6 years ago
Downloads
Today 4,230
This Week 18,224
This Month 92,311
Last Day 7,081
Last Week 39,496
Last Month 124,558
Dependencies (0)
None
Dev Dependencies (2)
Dependents (722)

Copyright 2014 - 2016 © taobao.org |