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.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",

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