diff --git a/index.js b/index.js index daf39c3..1502fc5 100644 --- a/index.js +++ b/index.js @@ -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 +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 diff --git a/package-lock.json b/package-lock.json index 05422c1..f7308c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { "name": "browser-stdout", - "version": "1.3.0", + "version": "1.3.1", "lockfileVersion": 1 }