Created
November 27, 2015 15:38
-
-
Save chauthai/cb6108b95c3b98bff175 to your computer and use it in GitHub Desktop.
A node polyfill for process.stderr in a browser
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
var WritableStream = require('stream'); | |
var inherits = require('util').inherits; | |
module.exports = BrowserStderr; | |
inherits(BrowserStderr, WritableStream); | |
function BrowserStderr(opts) { | |
if (!(this instanceof BrowserStderr)) return new BrowserStderr(opts); | |
opts = opts || {}; | |
WritableStream.call(this, opts); | |
this.label = (opts.label !== undefined) ? opts.label : 'stderr'; | |
} | |
BrowserStderr.prototype.write = function(chunks, encoding, cb) { | |
var output = chunks.toString ? chunks.toString() : chunks; | |
if (this.label === false) { | |
console.log(output); | |
} else { | |
console.log(this.label+':', output); | |
} | |
process.nextTick(cb); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment