events-to-array
Advanced tools
Comparing version 1.1.2 to 2.0.0
44
etoa.js
@@ -0,34 +1,28 @@ | ||
'use strict' | ||
const { EventEmitter } = require('events') | ||
module.exports = eventsToArray | ||
var EE = require('events').EventEmitter | ||
function eventsToArray (ee, ignore, map) { | ||
ignore = ignore || [] | ||
map = map || function (x) { return x } | ||
var array = [] | ||
function eventsToArray (ee, ignore = [], map = x => x) { | ||
const array = [] | ||
ee.emit = (function (orig) { | ||
return function etoaWrap (ev) { | ||
if (ignore.indexOf(ev) === -1) { | ||
var l = arguments.length | ||
var args = new Array(l) | ||
// intentionally sparse array | ||
var swap = [] | ||
for (var i = 0; i < l; i++) { | ||
var arg = arguments[i] | ||
args[i] = arguments[i] | ||
if (arg instanceof EE) | ||
swap[i] = eventsToArray(arg, ignore, map) | ||
const orig = ee.emit | ||
ee.emit = function (...args) { | ||
if (!ignore.includes(args[0])) { | ||
args = args.map((arg, i, arr) => { | ||
if (arg instanceof EventEmitter) { | ||
return eventsToArray(arg, ignore, map) | ||
} | ||
args = args.map(map) | ||
args = args.map(function (arg, index) { | ||
return swap[index] || arg | ||
}) | ||
array.push(args) | ||
} | ||
return orig.apply(this, arguments) | ||
return map(arg, i, arr) | ||
}) | ||
array.push(args) | ||
} | ||
})(ee.emit) | ||
return orig.apply(this, args) | ||
} | ||
return array | ||
} |
{ | ||
"name": "events-to-array", | ||
"version": "1.1.2", | ||
"version": "2.0.0", | ||
"description": "Put a bunch of emitted events in an array, for testing.", | ||
"main": "etoa.js", | ||
"directories": { | ||
"test": "test" | ||
"files": [ | ||
"etoa.js" | ||
], | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"tap": "^10.3.2" | ||
"tap": "^16.3.0" | ||
}, | ||
"scripts": { | ||
"test": "tap test/*.js --100", | ||
"test": "tap --100", | ||
"preversion": "npm test", | ||
@@ -16,0 +18,0 @@ "postversion": "npm publish", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
4359
4
20