pretty.js 807 B

1234567891011121314151617181920212223242526
  1. var inspect = require('util').inspect
  2. if(!module.parent) {
  3. var es = require('..') //load event-stream
  4. es.pipe( //pipe joins streams together
  5. process.openStdin(), //open stdin
  6. es.split(), //split stream to break on newlines
  7. es.map(function (data, callback) {//turn this async function into a stream
  8. var j
  9. try {
  10. j = JSON.parse(data) //try to parse input into json
  11. } catch (err) {
  12. return callback(null, data) //if it fails just pass it anyway
  13. }
  14. callback(null, inspect(j)) //render it nicely
  15. }),
  16. process.stdout // pipe it to stdout !
  17. )
  18. }
  19. // run this
  20. //
  21. // curl -sS registry.npmjs.org/event-stream | node pretty.js
  22. //