npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

events-to-array

v2.0.3

Published

Put a bunch of emitted events in an array, for testing.

Downloads

1,604,514

Readme

events-to-array

Put a bunch of emitted events in an array, for testing.

If any of the emitted arguments are event emitters, then they'll also be tracked, and replaced in the array with their tracking array. (This is less confusing in practice than it sounds in text, see below.) The only caveat is that the events in the child event emitter and in the parent are not preserved in order, so this lib doesn't tell you whether the child events happened before or after any subsequent parent events.

USAGE

var assert = require('assert')
var EE = require('events')
var etoa = require('events-to-array')
var emitter = new EE()
var array = etoa(emitter)

emitter.emit('foo', 1, 2, 3)
emitter.emit('bar', { x: 1 })

// nested events get tracked as well
var subemit = new EE()
emitter.emit('sub', subemit)
subemit.emit('childEvent', { some: 'data' })
subemit.emit('anotherone', { some: 'data' }, 'many', 'args')

// CAVEAT!  See above in the wordy part of this readme.
// Note that the blaz/blorrg event comes after the child, and there's
// no way to know that the child 'order not preserved' event happened
// after.
emitter.emit('blaz', 'blorrg')
subemit.emit('order', 'not', 'preserved between child and parent')

// check out the array whenever
assert.deepEqual(array,
[ [ 'foo', 1, 2, 3 ],
  [ 'bar', { x: 1 } ],
  [ 'sub',
    [ [ 'childEvent', { some: 'data' } ],
      [ 'anotherone', { some: 'data' }, 'many', 'args' ],
      [ 'order', 'not', 'preserved between child and parent' ] ] ],
  [ 'blaz', 'blorrg' ] ])

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

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 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)