Socket
Socket
Sign inDemoInstall

mute-stream

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 0.0.2

18

mute.js

@@ -7,7 +7,9 @@ var Stream = require('stream')

// argument auto-pipes
function MuteStream (dest) {
function MuteStream (opts) {
Stream.apply(this)
opts = opts || {}
this.writable = this.readable = true
this.muted = false
this.on('pipe', this._onpipe)
this.replace = opts.replace
}

@@ -79,3 +81,6 @@

MuteStream.prototype.write = function (c) {
if (this.muted) return true
if (this.muted) {
if (!this.replace) return true
c = c.toString().replace(/./g, this.replace)
}
this.emit('data', c)

@@ -85,3 +90,10 @@ }

MuteStream.prototype.end = function (c) {
if (!this.muted) this.emit('data', c)
if (this.muted) {
if (c && this.replace) {
c = c.toString().replace(/./g, this.replace)
} else {
c = null
}
}
if (c) this.emit('data', c)
this.emit('end')

@@ -88,0 +100,0 @@ }

2

package.json
{
"name": "mute-stream",
"version": "0.0.1",
"version": "0.0.2",
"main": "mute.js",

@@ -5,0 +5,0 @@ "directories": {

@@ -13,3 +13,3 @@ # mute-stream

var ms = new MuteStream
var ms = new MuteStream(options)

@@ -38,2 +38,10 @@ ms.pipe(process.stdout)

## Options
All options are optional.
* `replace` Set to a string to replace each character with the
specified string when muted. (So you can show `****` instead of the
password, for example.)
## ms.mute()

@@ -40,0 +48,0 @@

@@ -136,1 +136,60 @@ var Stream = require('stream')

})
tap.test('replace with *', function (t) {
var str = new PassThrough
var ms = new MS({replace: '*'})
str.pipe(ms)
var expect = ['foo', '*****', 'bar', '***', 'baz', 'boo', '**', '****']
ms.on('data', function (c) {
t.equal(c, expect.shift())
})
str.write('foo')
ms.mute()
str.write('12345')
ms.unmute()
str.write('bar')
ms.mute()
str.write('baz')
ms.unmute()
str.write('baz')
str.write('boo')
ms.mute()
str.write('xy')
str.write('xyzΩ')
t.equal(expect.length, 0)
t.end()
})
tap.test('replace with ~YARG~', function (t) {
var str = new PassThrough
var ms = new MS({replace: '~YARG~'})
str.pipe(ms)
var expect = ['foo', '~YARG~~YARG~~YARG~~YARG~~YARG~', 'bar',
'~YARG~~YARG~~YARG~', 'baz', 'boo', '~YARG~~YARG~',
'~YARG~~YARG~~YARG~~YARG~']
ms.on('data', function (c) {
t.equal(c, expect.shift())
})
// also throw some unicode in there, just for good measure.
str.write('foo')
ms.mute()
str.write('ΩΩ')
ms.unmute()
str.write('bar')
ms.mute()
str.write('Ω')
ms.unmute()
str.write('baz')
str.write('boo')
ms.mute()
str.write('Ω')
str.write('ΩΩ')
t.equal(expect.length, 0)
t.end()
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc