source: trip-planner-front/node_modules/merge-stream/README.md@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1# merge-stream
2
3Merge (interleave) a bunch of streams.
4
5[![build status](https://secure.travis-ci.org/grncdr/merge-stream.svg?branch=master)](http://travis-ci.org/grncdr/merge-stream)
6
7## Synopsis
8
9```javascript
10var stream1 = new Stream();
11var stream2 = new Stream();
12
13var merged = mergeStream(stream1, stream2);
14
15var stream3 = new Stream();
16merged.add(stream3);
17merged.isEmpty();
18//=> false
19```
20
21## Description
22
23This 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
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```js
46stream = require('merge-stream')();
47// Something like a loop to add some streams to the merge stream
48// stream.add(streamA);
49// stream.add(streamB);
50return stream.isEmpty() ? null : stream;
51```
52
53## Gulp example
54
55An example use case for **merge-stream** is to combine parts of a task in a project's **gulpfile.js** like this:
56
57```js
58const 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## License
77
78MIT
Note: See TracBrowser for help on using the repository browser.