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

small-events-ts

v1.0.1

Published

Type-safe event dispatcher utility for JS/TS

Readme

Small Events Ts

npm version license tests coverage

A lightweight hierarchical asynchronous event dispatcher for TypeScript projects.

  • Async dispatch
  • Hierarchical selectors (a:b:c triggers a, a:b, a:b:c)
  • once() listeners
  • stopPropagation() support
  • Remove listeners
  • Zero dependencies
  • Works in Svelte, Node, Vite, SSR

Installation

npm install small-events-ts

or

pnpm add small-events-ts

Why this exists

JavaScript has:

  • window.addEventListener → only global and DOM-related
  • Node EventEmitter → no hierarchy, no async ordering guarantees
  • Svelte stores → no event bus pattern

This library provides:

  • namespaced events ui:modal:open
  • hierarchical propagation ui → ui:modal → ui:modal:open
  • predictable async order
  • full control over propagation
  • small & dependency-free

Usage

import { EventDispatcher } from "small-events-ts";

const dispatcher = new EventDispatcher();

dispatcher.listen("test", (event) => {
  console.log(event.data);
});

dispatcher.dispatch({ selector: "test", data: "Hello" });

Output:

Hello

Hierarchical Selectors

dispatcher.listen("a", () => console.log("root"));
dispatcher.listen("a:b", () => console.log("sub"));

dispatcher.dispatch({ selector: "a:b", data: null });

Output:

root
sub

Async Dispatch

dispatcher.listen("async", async () => {
  await new Promise(r => setTimeout(r, 100));
  console.log("async done");
});

dispatcher.listen("async", () => {
  console.log("sync");
});

await dispatcher.dispatch({ selector: "async", data: null });

Output:

async done
sync
  • Listeners run in order and await async handlers

Once Listeners

dispatcher.once("load", () => console.log("only once"));
dispatcher.dispatch({ selector: "load", data: null });
dispatcher.dispatch({ selector: "load", data: null });

Output:

only once

Stop Propagation

dispatcher.listen("x", (e) => {
  console.log("first");
  e.stopPropagation();
});

dispatcher.listen("x", () => console.log("second"));

dispatcher.dispatch({ selector: "x", data: null });

Output:

first
  • The second listener is not called

Remove Listener

const fn = () => console.log("removed");
dispatcher.listen("event", fn);
dispatcher.remove("event", fn);

dispatcher.dispatch({ selector: "event", data: null });
  • Listener is removed

API Documentation

Event

interface Event {
  selector: string;
  data: any;
  stopPropagation(): void;
}

EventDispatcher

listen(selector, callable)

Registers a listener.

once(selector, callable)

Registers a listener that auto-removes after first call.

dispatch(event)

Triggers all matching listeners in order.

Supports:

  • async listeners
  • stopPropagation
  • hierarchical selectors

remove(selector, callable)

Removes a specific listener.


Advanced Usage

Return unsubscribe

const off = dispatcher.listen("chat", handler);

// later
off();

Global event bus (Svelte)

src/lib/events.ts:

import { EventDispatcher } from "small-events-ts";
export const events = new EventDispatcher();

Use in components:

<script>
  import { events } from "$lib/events";

  events.listen("ui:open", () => modal = true);
</script>

Trigger:

<script>
  import { events } from "$lib/events";
  events.dispatch({ selector: "ui:open" });
</script>

Unit Tests

This package includes full Vitest coverage.

Run tests:

npm test

Coverage:

100%

Roadmap

  • Svelte integration
  • TypeScript types
    ⬜ Wildcard selectors (ui:*)
    ⬜ Selector filtering (ui:**)
    ⬜ Plugin system

License

MIT © Sébastien Kus