Security update to Drupal 8.4.6
[yaffs-website] / node_modules / fork-stream / README.md
1 fork-stream [![build status](https://travis-ci.org/deoxxa/fork-stream.png)](https://travis-ci.org/deoxxa/fork-stream)
2 ===========
3
4 Fork a stream in multiple directions according to a function.
5
6 Overview
7 --------
8
9 fork-stream basically gives you conditional branching for streams. You supply
10 the logic, fork-stream supplies the streaming.
11
12 Super Quickstart
13 ----------------
14
15 Code:
16
17 ```javascript
18 var ForkStream = require("fork-stream");
19
20 var fork = new ForkStream({
21   classifier: function classify(e, done) {
22     return done(null, e.match(/[aeiou]/));
23   },
24 });
25
26 fork.a.on("data", console.log.bind(console, "vowels:"));
27 fork.b.on("data", console.log.bind(console, "no vowels:"));
28
29 fork.write("hello");
30 fork.write("zxcbzz");
31 fork.write("ooooooo");
32
33 fork.end();
34 ```
35
36 Output:
37
38 ```
39 vowels: hello
40 no vowels: zxcbzz
41 vowels: ooooooo
42 ```
43
44 Installation
45 ------------
46
47 Available via [npm](http://npmjs.org/):
48
49 > $ npm install fork-stream
50
51 Or via git:
52
53 > $ git clone git://github.com/deoxxa/fork-stream.git node_modules/fork-stream
54
55 API
56 ---
57
58 **constructor**
59
60 Creates a new fork-stream.
61
62 ```javascript
63 new ForkStream(options);
64 ```
65
66 ```javascript
67 var fork = new ForkStream({
68   highWaterMark: 5,
69   classifier: function(e, done) {
70     return done(null, !!e);
71   },
72 });
73 ```
74
75 * _options_ - regular stream options, and a `classifier` property that
76   fork-stream will use to decide what output stream to send your object down.
77
78 Example
79 -------
80
81 Also see [example.js](https://github.com/deoxxa/fork-stream/blob/master/example.js).
82
83 ```javascript
84 var ForkStream = require("fork-stream");
85
86 var fork = new ForkStream({
87   classifier: function classify(e, done) {
88     return done(null, e >= 5);
89   },
90 });
91
92 fork.a.on("data", console.log.bind(null, "a"));
93 fork.b.on("data", console.log.bind(null, "b"));
94
95 for (var i=0;i<20;++i) {
96   fork.write(Math.round(Math.random() * 10));
97 }
98 ```
99
100 Output:
101
102 ```
103 b 1
104 a 6
105 a 9
106 a 10
107 a 7
108 a 5
109 b 2
110 b 4
111 a 8
112 b 3
113 a 5
114 b 4
115 a 7
116 a 8
117 b 1
118 a 6
119 b 2
120 b 0
121 a 5
122 b 1
123 ```
124
125 License
126 -------
127
128 3-clause BSD. A copy is included with the source.
129
130 Contact
131 -------
132
133 * GitHub ([deoxxa](http://github.com/deoxxa))
134 * Twitter ([@deoxxa](http://twitter.com/deoxxa))
135 * Email ([deoxxa@fknsrs.biz](mailto:deoxxa@fknsrs.biz))