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

@yoshibu/events

v1.0.3

Published

fast event emitter

Downloads

6

Readme

events

Fast event emitter for javascript. Check the benchmarks.

This is the benchmark result that emit event to the single listener

event-emitter x 6,300,170 ops/sec ±1.59% (94 runs sampled)
EventEmitter2 x 10,258,851 ops/sec ±0.54% (92 runs sampled)
EventEmitter3 x 12,151,111 ops/sec ±0.30% (91 runs sampled)
component-emitter x 2,663,473 ops/sec ±0.77% (94 runs sampled)
wolfy87-eventemitter x 2,081,167 ops/sec ±0.48% (95 runs sampled)
@foxify/events x 19,033,563 ops/sec ±0.72% (92 runs sampled)
@yoshibu/events x 20,305,984 ops/sec ±0.43% (93 runs sampled)
Fastest is @yoshibu/events

Features

  • Fast
  • Compiled by the buble, and the compile target is 'ie8'
  • Support ES2015 module, CommonJS, and the browser
  • Support Wildcard event

Install

npm

npm i @yoshibu/events

CDN

<script src="https://unpkg.com/@yoshibu/events/dist/events.browser.js"></script>

You can find the library on window.EventEmitter

Usage

import EventEmitter from '@yoshibu/events'
// const EventEmitter = require('@yoshibu/events') // CommonJS

const emitter = new EventEmitter();

// listen to an event
emitter.on('foo', message => console.log(message));

// listen to all events
emitter.on('*', (event, message) => console.log(event, message));

emitter.emit('foo', 'hello');
// --- console ---
// foo hello
// hello

API

addListener(event, listener)

Alias for the on

on(event, listener)

  • event: string
  • listener: function
  • Returns: EventEmitter

Register an event listener for the given event.

import EventEmitter from '@yoshibu/events'

const ee = new EventEmitter();

ee.on('foo', message => console.log(message));

If you specified '*' for the event, the listener will be invoked with an event name and the arguments when any events emitted.

import EventEmitter from '@yoshibu/events'

const ee = new EventEmitter();

ee.on('*', console.log);

ee.emit('foo', 1, 2, 3);
// --- console ---
// foo 1 2 3

once(event, listener)

  • event: string
  • listener: function
  • Returns: EventEmitter

Register an one-time event listener for the given event.

import EventEmitter from '@yoshibu/events'

const ee = new EventEmitter();

ee.once('foo', message => console.log(message));

emit(event[, ...args])

  • event: string
  • args: any
  • Returns: boolean

Synchronously invoke each of the listeners registered for the given event, passing the supplied arguments to each.

Returns true if the event had listeners, false otherwise.

import EventEmitter from '@yoshibu/events'

const ee = new EventEmitter();

ee.emit('foo', 1, 2, 3);

Event listener execution order

  1. Listeners registered for the '*' event by the once method
  2. Listeners registered for the'*' event by the addListener or on method
  3. Listeners registered for the given event by the once method
  4. Listeners registered for the given event by the addListener or on method
import EventEmitter from '@yoshibu/events'

const ee = new EventEmitter();

ee
  .on('foo', () => console.log('on: foo'))
  .once('foo', () => console.log('once: foo'))
  .on('*', () => console.log('on: *'))
  .once('*', () => console.log('once: *'));

ee.emit('foo');
// --- console ---
// once: *
// on: *
// once: foo
// on: foo

removeListener(event, listener)

  • event: string
  • listener: function
  • Retusns: EventEmitter

Remove all specified listeners from the given event.

import EventEmitter from '@yoshibu/events'

const ee = new EventEmitter();

const listener = () => {};

ee.on('foo', listener);

ee.removeListener('foo', listener);

removeAllListeners([event])

  • event: string
  • Returns: EventEmitter

Remove all listeners from the given event. If event is not passed, remove all listeners.

import EventEmitter from '@yoshibu/events'

const ee = new EventEmitter();

ee.removeAllListeners('foo');

listenerCount(event)

  • event: string
  • Returns: number

Returns the listener count for the given event.

import EventEmitter from '@yoshibu/events'

const ee = new EventEmitter();

ee.listenerCount('foo'); // 0

Liccence

MIT License © YooShibu