Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

events-to-array

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

events-to-array - npm Package Compare versions

Comparing version 1.0.2 to 1.1.2

.nyc_output/4be8269da653889d36701d080e519360.json

15

etoa.js
module.exports = eventsToArray
var EE = require('events').EventEmitter
function eventsToArray (ee, ignore) {
function eventsToArray (ee, ignore, map) {
ignore = ignore || []
map = map || function (x) { return x }
var array = []

@@ -13,8 +14,14 @@

var args = new Array(l)
// intentionally sparse array
var swap = []
for (var i = 0; i < l; i++) {
var arg = arguments[i]
args[i] = (arg instanceof EE) ?
eventsToArray(arg, ignore) :
arg
args[i] = arguments[i]
if (arg instanceof EE)
swap[i] = eventsToArray(arg, ignore, map)
}
args = args.map(map)
args = args.map(function (arg, index) {
return swap[index] || arg
})
array.push(args)

@@ -21,0 +28,0 @@ }

{
"name": "events-to-array",
"version": "1.0.2",
"version": "1.1.2",
"description": "Put a bunch of emitted events in an array, for testing.",

@@ -11,6 +11,9 @@ "main": "etoa.js",

"devDependencies": {
"tap": "^0.7.1"
"tap": "^10.3.2"
},
"scripts": {
"test": "tap test/*.js"
"test": "tap test/*.js --100",
"preversion": "npm test",
"postversion": "npm publish",
"postpublish": "git push origin --all; git push origin --tags"
},

@@ -17,0 +20,0 @@ "repository": {

@@ -49,3 +49,3 @@ # events-to-array

## `eventsToArray(emitter, [ignoreList])`
## `eventsToArray(emitter, [ignoreList], [mapFunction])`

@@ -55,2 +55,15 @@ Returns an array with all the events emitted by the emitter.

It's your responsibility to know when to check it for the events that
you expect.
you expected to have received.
The `ignoreList` is an array of event names to ignore.
The `mapFunction` is a function that takes a list of arguments and
returns a potentially-mutated array of arguments. Note that child
event emitters will already have been swapped out for an
events-to-array list so that nested events are caught.
This is handy, for example, for swapping out large `Buffer` objects
with something like `{type: 'buffer', length: 123456}` rather than
blow up the JSON fixtures.
The map function is called on the args list as `map(arg, index, list)`

@@ -35,1 +35,32 @@ var test = require('tap').test

})
test('ignore nothing', function (t) {
var emitter = new EE()
var array = etoa(emitter)
emitter.emit('foo', 1, 2, 3)
emitter.emit('ignore', 'should see this')
emitter.emit('bar', { x: 1 })
t.same(array,
[ [ 'foo', 1, 2, 3 ],
[ 'ignore', 'should see this' ],
[ 'bar', { x: 1 } ] ])
t.end()
})
test('the map is not the territory', function (t) {
var emitter = new EE()
// cast all to strings
var array = etoa(emitter, ['ignore'], function (arg) {
return arg + ''
})
emitter.emit('foo', new Buffer('hello'))
var sub = new EE()
emitter.emit('sub', sub)
sub.emit('obj', { toString: function () { return 'toString fn' } })
t.same(array,
[ ['foo', 'hello' ],
[ 'sub', [ [ 'obj', 'toString fn' ] ] ] ])
t.end()
})
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc