Skip to content

Instantly share code, notes, and snippets.

@qcom
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qcom/29b9a205bd3ed92293b5 to your computer and use it in GitHub Desktop.
Save qcom/29b9a205bd3ed92293b5 to your computer and use it in GitHub Desktop.
#####################################################################
## ~~ 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