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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@rsol/ebus

v1.0.0

Published

EventBus flexible event bus emit/pubsub

Readme

EventBus

EventBus flexible event bus emit/pubsub weighs less than 1KB. Wildcard support. Based on Node's EventEmitter

Table of Contents

Install

This project uses node and npm. Go check them out if you don't have them locally installed.

$ npm install --save @rsol/ebus

Then with a module bundler like rollup or webpack, use as you would anything else:

// using ES6 modules
import EventBus, { getEventBus, removeEventBus, hasEventBus } from '@rsol/ebus'

// using CommonJS modules
const EventBus = require('@rsol/ebus')

Usage

const global = EventBus.getInstance();

const bus = EventBus.getInstance('Bus', {
  wildcard: true,
  maxListeners: 5
});

let i = 1;
const addF = (add: number) => i += add;
const subF = (sub: number) => i -= sub;
const mulF = (mul: number) => i *= mul;
const divF = (div: number) => i /= div;

bus
  .on('wildcard.add', addF)
  .on('wildcard.sub', subF)
  .on('wildcard.mul', mulF)
  .on('wildcard.div', divF)
  .emit('wildcard.*', 10);
console.log(i); // 1

bus.emit('wildcard.add', 2);
console.log(i); // 3

const result = bus
  .removeListener('wildcard.div', divF)
  .emit('wildcard.*', 10);
console.log(i); // 30

console.log(result);
/**
 * Map(3) {
 'wildcard.add' => true,
 'wildcard.sub' => true,
 'wildcard.mul' => true
 }
 */

console.log(bus.listenerCount('wildcard.*')); //3 

bus.removeAllListeners('wildcard.\[div|mul\]')

console.log(wildcardEb.eventNames());//['wildcard.add', 'wildcard.sub']

To find more examples see test folder. For more methods see API

API

Table of Contents

EventBus

EventBus flexible event bus emit/pubsub

getBus

Returns EventEmitter

getBusName

Returns (string | Symbol)

close

Remove EventBus instance and corresponding EventEmitter

on

Alias for addListener(eventName, listener) addListener

Parameters

Returns EventBus

once

Adds a one-timelistener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked

Parameters

Returns EventBus

off

Alias for removeListener(eventName, listener) removeListener

Parameters

Returns EventBus

addListener

Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times

Parameters

Returns EventBus

removeListener

Removes the specified listener from the listener array for the event namedeventName

Parameters

Returns EventBus

removeAllListeners

Removes all listeners, or those of the specified eventName

Parameters

Returns void

setMaxListeners

By default, EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps to find memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance

Parameters

Returns EventBus

getMaxListeners

Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n)

Returns number

listeners

Returns a copy of the array of listeners for the event named eventName

Parameters

Returns Array<function>

emit

Synchronously calls each of the listeners registered for the event namedeventName, in the order they were registered, passing the supplied arguments to each

Parameters

Returns Map<(string | Symbol), boolean>

eventNames

Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols

Returns Array<EventName>

matchedEventNames

Returns a matched array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols

Parameters
  • eventName EventName

Returns Array<EventName>

listenerCount

Returns the number of listeners listening for the event named eventName. If listener is provided, it will return how many times the listener is found in the list of the listeners of the event

Parameters

Returns number

getInstance

Get EventBus instance

Parameters
  • name (string | Symbol) (optional, default 'GLOBAL')

  • options Object?

    • options.wildcard boolean Is use wildcard for emit, listenerCount and removeAllListeners methods (optional, default false)
    • options.maxListeners number Max number of listeners (optional, default 50)

Returns EventBus

hasBus

Parameters

Returns boolean

getEventBus

Return specific EventEmitter by name

Parameters

Returns EventEmitter

removeEventBus

Remove specific EventEmitter by name

Parameters

Returns void

hasEventBus

Check if specific EventEmitter by name exists

Parameters

Returns boolean

License

MIT License © Jason Miller