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

event-manager-typescript

v0.1.2

Published

A modern TypeScript event manager: easy to use, lightweight, and a joy to work with.

Readme

Event Manager TypeScript

English | 简体中文

🎉 A Modern TypeScript Event Manager – Easy-to-use, Lightweight, and Developer-friendly.

🔒 Type Safety

Enjoy full type hints and validation from event definition to usage, and say goodbye to runtime errors.

🧩 Zero Dependencies

Lightweight with no external dependencies, it can be seamlessly integrated into any project.

💖 Developer Experience

Every API is designed to deliver an intuitive and human-centric development experience.

📦 Installation

npm install event-manager-typescript

yarn add event-manager-typescript

pnpm add event-manager-typescript

🚀 Quick Start

import { EventManager } from "event-manager-typescript";

// Define event types (highly recommended).
// You can use them either via the strict EVENT_TYPE.XXX or the "xxx" literal value.
// Suitable for both underlying and business logic, especially useful during refactoring.
const EVENT_TYPE = {
    Work: "work",
    Sleep: "sleep",
} as const;
type EVENT_TYPE = typeof EVENT_TYPE[keyof typeof EVENT_TYPE];

// Define event type mapping
interface EVENT_TYPE_MAP {
    [EVENT_TYPE.Work]: (name: string, time: number) => void;
    [EVENT_TYPE.Sleep]: (name: string, time: number) => void;
}

// Literal-based event type mapping (not recommended, but optional)
// interface EVENT_TYPE_MAP {
//     "work": (name: string, time: number) => void;
//     "sleep": (name: string, time: number) => void;
// }

// Create an event manager instance
const eventManager = new EventManager<EVENT_TYPE_MAP>();

// Get all event nodes of the specified event type
const workNodes = eventManager.getEventNodes(EVENT_TYPE.Work);
const sleepNodes = eventManager.getEventNodes(EVENT_TYPE.Sleep);

🎧 Listening to Events

// Listener without a context target
const onWork = (name: string, time: number)  => {
    console.log(`${name} starts working, duration: ${time} minutes.`);
};
eventManager.on(EVENT_TYPE.Work, onWork);

// Listener with a context target
const target = {};
eventManager.on(EVENT_TYPE.Work, onWork, target);

// Returns the unsubscription function and event ID
const [offSleep, sleepId] = eventManager.on(EVENT_TYPE.Sleep, (name, time) => {
    console.log(`${name} starts sleeping, duration: ${time} minutes.`);
});
  • Parameter Type Hints alt text
  • Literal Event Type Hints alt text

🚫 Unsubscribing from Events

// Unsubscribe via the bound listener and context target
eventManager.off(EVENT_TYPE.Work, onWork);
eventManager.off(EVENT_TYPE.Work, onWork, target);

// Unsubscribe via the returned unsubscription function
offSleep();

// Unsubscribe via the returned event ID
eventManager.off(sleepId);

// Unsubscribe all events of the specified type
eventManager.offAll(EVENT_TYPE.Work);
eventManager.offAll(EVENT_TYPE.Sleep);

// Unsubscribe all events
eventManager.offAll();
  • Parameter Type Hints alt text
  • Literal Event Type Hints alt text

🚀 Emitting Events

eventManager.emit(EVENT_TYPE.Work, "Alice", 30);
eventManager.emit(EVENT_TYPE.Sleep, "Bob", 15);
  • Parameter Type Hints alt text
  • Literal Event Type Hints alt text

🧩 Getting Status Info

const info = eventManager.getStatusInfo();
console.log(info);

🛠️ Development

Dependencies

  • TypeScript: TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.
  • tsdown: An elegant library bundler
  • nodemon: Monitors for any changes in your source code and automatically restarts the server.

Install Dependencies

npm install

Development

npm run dev

Build

npm run build