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

safe-event-emitter-ts

v0.1.1

Published

A fully type-safe EventEmitter implementation for TypeScript with API similar to Node.js EventEmitter.

Downloads

3

Readme

safe-event-emitter-ts

A fully type-safe EventEmitter implementation for TypeScript with API similar to Node.js EventEmitter.

Features

  • 🔒 Full TypeScript type safety for events and their payloads
  • 🔄 API compatible with Node.js EventEmitter
  • 🌳 Support for wildcard event patterns (optional)
  • ⚡ Async event handling support
  • 🎯 Zero dependencies
  • 💪 Robust error handling

Installation

# Using bun
bun add safe-event-emitter-ts

Basic Usage

import { EventEmitter } from 'safe-event-emitter-ts';

// Define your event map with type-safe event names and parameters
interface MyEvents {
  userJoined: [username: string, timestamp: number];
  userLeft: [username: string];
  messageReceived: [message: string, from: string];
}

// Create a type-safe event emitter instance
const emitter = new EventEmitter<MyEvents>();

// Add event listeners with full type safety
emitter.on('userJoined', (username, timestamp) => {
  console.log(`${username} joined at ${new Date(timestamp)}`);
});

emitter.on('messageReceived', (message, from) => {
  console.log(`${from}: ${message}`);
});

// Emit events with type checking
emitter.emit('userJoined', 'Alice', Date.now()); // ✅ Valid
emitter.emit('messageReceived', 'Hello!', 'Bob'); // ✅ Valid
emitter.emit('userJoined', 'Alice'); // ❌ Type error: missing timestamp

Advanced Features

Wildcard Event Patterns

// Enable wildcard support in constructor
const emitter = new EventEmitter<MyEvents>({ useWildcards: true });

// Listen to all events matching a pattern
emitter.on('user*', (username) => {
  console.log('User event occurred:', username);
});

// Use deep wildcards
emitter.on('chat.**', (...args) => {
  console.log('Chat related event:', ...args);
});

Async Event Handling

// Async event handler
emitter.on('messageReceived', async (message, from) => {
  await saveToDatabase(message, from);
}, { promisify: true });

// Emit and wait for all handlers
await emitter.emitAsync('messageReceived', 'Hello!', 'Alice');

Once Listeners

// Listen for an event only once
emitter.once('userJoined', (username, timestamp) => {
  console.log(`First user ${username} joined!`);
});

Node.js EventEmitter Compatibility

This package implements an API similar to Node.js EventEmitter, making it familiar for Node.js developers. Key differences include:

  • Full TypeScript type safety
  • Optional wildcard event support
  • Built-in async event handling
  • More robust error handling

Common methods like on(), once(), emit(), and off() work the same way as in Node.js EventEmitter.

Configuration Options

const emitter = new EventEmitter<MyEvents>({
  useWildcards: false,         // Enable/disable wildcard support
  namespaceDelimiter: '.',     // Delimiter for event namespaces
  emitNewListener: false,      // Emit 'newListener' events
  emitRemoveListener: false,   // Emit 'removeListener' events
  maxHandlers: 10,             // Max listeners per event
  suppressErrors: false,       // Suppress error events
  detailedLeakWarnings: true   // Show detailed memory leak warnings
});

Credits

This implementation is inspired by the awesome EventEmitter2.

License

MIT