Last active
August 29, 2015 14:02
-
-
Save qcom/29b9a205bd3ed92293b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##################################################################### | |
## ~~ HTML STREAM ~~ ## | |
##################################################################### | |
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. | |
Make sure to `npm install trumpet through` in the directory where your solution | |
file lives. | |
To verify your program, run: `stream-adventure verify program.js`. | |
--------------------------------- | |
--------------------------------- | |
var trumpet = require('trumpet'); | |
var through = require('through'); | |
var tr = trumpet(); | |
process.stdin.pipe(tr).pipe(process.stdout); | |
var stream = tr.select('.loud').createStream(); | |
stream.pipe(through(function(chunk) { | |
this.queue(chunk.toString().toUpperCase()); | |
})).pipe(stream); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment