-
Notifications
You must be signed in to change notification settings - Fork 0
/
html_stream.js
34 lines (22 loc) · 989 Bytes
/
html_stream.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
*Your program will get some html written to stdin. Convert all the inner html to
upper-case for elements with a class name of "loud".
You can use `trumpet` and `through` to solve this adventure.
With `trumpet` you can create a transform stream from a css selector:
var trumpet = require('trumpet');
var fs = require('fs');
var tr = trumpet();
fs.createReadStream('input.html').pipe(tr);
var stream = tr.select('.beep').createStream();
Now `stream` outputs all the inner html content at `'.beep'` and the data you
write to `stream` will appear as the new inner html content.
*/
var trumpet = require('trumpet');
var through = require('through');
var trumpet = trumpet();
var stream = trumpet.select('.loud').createStream();
stream.pipe(through(function(data) {
this.queue(data.toString().toUpperCase());
})).pipe(stream);
//stream.pipe(through(function(data){this.queue(data.toString().toUpperCase())}, null));
process.stdin.pipe(trumpet).pipe(process.stdout);