Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
var WritableStream = require('stream').Writable
var inherits = require('util').inherits
const { Writable } = require('stream')
const { inherits } = require('util')

module.exports = BrowserStdout


inherits(BrowserStdout, WritableStream)

function BrowserStdout(opts) {
const BrowserStdout = function (opts) {
if (!(this instanceof BrowserStdout)) return new BrowserStdout(opts)

opts = opts || {}
WritableStream.call(this, opts)
this.label = (opts.label !== undefined) ? opts.label : 'stdout'

Writable.call(this, opts)

this.label = (typeof opts.label === 'undefined') ? 'stdout' : opts.label
}

BrowserStdout.prototype._write = function(chunks, encoding, cb) {
var output = chunks.toString ? chunks.toString() : chunks
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this check?

image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont remember why its there, though its certainly possible to pass in a value that does not have a toString method. Fallback should likely be String(chunks)

BrowserStdout.prototype._write = function (chunks, encoding, cb) {
const output = chunks.toString ? chunks.toString() : chunks

if (this.label === false) {
console.log(output)
} else {
console.log(this.label+':', output)
console.log(this.label + ':', output)
}

process.nextTick(cb)
}

inherits(BrowserStdout, Writable)

module.exports = BrowserStdout
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.