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 🙏

© 2026 – Pkg Stats / Ryan Hefner

wildcard-event

v1.0.2

Published

Anything can be the event identifier. Tis a simple EventBus module for js/ts projects, support wildcards

Downloads

5

Readme

A lightweight, flexible event bus for JavaScript/TypeScript. Supports any type of event identifier, wildcard event names, and listener capacity control. You can even get an id from eventBus.on and get emit result from eventBus.emit!

For more awesome packages, check out my homepage💛


Installation

pnpm add wildcard-event
# or
npm install wildcard-event

Basic Usage

import { eventBus } from 'wildcard-event';

// Wildcard support
eventBus.on('user.*', () => console.log('Any user event!'));
eventBus.emit('user.logout'); // triggers wildcard

// Emit
const emitResult = eventBus.emit('user.login', { name: 'Alice' });

// Set the name of the eventBus
eventBus.name; // it is readonly
eventBus.setName('MyEventBus'); // eventBus.name is now 'MyEventBus'

Breaking Feature!

emit method now returns an object(interface: EmitResult). With the identifier-listener entry id, you can get the specific handler result if you want to.

// save the unique 'identifier-listener' id returned from `on` method
const listener = (user) => {
  console.log('User logged in:', user);
};
const id = eventBus.on('user.*', listener);

// emit an event and receive its result
const emitResult = eventBus.emit('user.login', { name: 'Alice' });

Then the emitResult will look like this:

expect(emitResult).toEqual({
  ids: [id], // array of listener ids that were triggered
  [id]: {
    identifier: 'user.*', // the matched identifier when it was registered
    result: listener({ name: 'Alice' }), // result of the listener
    rest: Infinity, // remaining capacity (if set)
  },
});

Note: The listener can be an async function, which makes emitResult[someId].result a Promise.

API

eventBus.on(identifier, listener, capacity?)

Register a listener for an event. identifier can be any value. capacity (optional) limits how many times the listener can be triggered.

  • Default capacity is Infinity.
  • When emitting, the listeners will be called in the order they were registered.

eventBus.once(identifier, listener)

Register a listener that will be triggered only once.

eventBus.off(identifier)

Remove all listeners for the given event identifier.

eventBus.removeListener(id)

Remove a specific listener by its id (returned from on/once).

eventBus.emit(identifier, ...args)

Trigger an event. Returns null if no listener is found, or an object with results and remaining capacity.

Wildcard Rules

  1. * matches a single segment (e.g. user.* matches user.login, not user.profile.update)
  2. ** matches multiple segments (e.g. user.** matches user.login, user.profile.update, user.settings.privacy.change, and user itself)
  3. Cannot use both ** and * in the same identifier
  4. Cannot use more than 2 *s, like *** or more
  5. Cannot start or end with a dot (.).
  6. Mixed: user.*.settings matches user.admin.settings, user.guest.settings
  7. Only registration (on/once) supports wildcards; emit must use concrete event names

Types

type Fn = (...args: unknown[]) => unknown;
interface EventConfig {
  listener: Fn;
  capacity: number;
}
interface EmitResultValue {
  identifier: unknown;
  result: unknown;
  rest: number;
}
interface EmitResult {
  ids: number[];
  [key: number]: EmitResultValue;
}

Author

Kasukabe Tsumugi
[email protected]


Enjoy! (づ。◕‿‿◕。)づ