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-kit/bus

v0.1.3

Published

Zero-dependency, type-safe, cross-tab event bus with pluggable transports (BroadcastChannel, LocalStorage, WebSocket, ...).

Readme

@event-kit/bus

Zero-dependency, fully-typed, cross-tab event bus for the browser. Ships with BroadcastChannel and localStorage transports out of the box, and a single Transport interface for adding your own (WebSocket, SharedWorker, ...).

Install

npm install @event-kit/bus

Quick start

extends EventMap is required, not decorative. EventMap is Record<string, unknown>; TypeScript only recognizes your interface as satisfying T extends EventMap once it structurally carries an index signature, which extends supplies. Leaving it off compiles your interface fine but fails later, at new Dispatcher<AppEvents>(), with a confusing "does not satisfy the constraint" error.

import { createDispatcher, type EventMap } from '@event-kit/bus';

interface AppEvents extends EventMap {
  'auth:login': { userId: string; token: string };
  'auth:logout': { reason?: 'expired' | 'manual' };
}

const bus = createDispatcher<AppEvents>({
  channelName: 'my-app-v1',   // enables BroadcastChannelTransport
  localStoragePrefix: 'app:', // enables LocalStorageTransport fallback
});

const unsubscribe = bus.on('auth:login', ({ userId, token }) => {
  console.log(userId, token); // fully typed, no casts
});

bus.emit('auth:login', { userId: '123', token: 'abc' });

// Later:
unsubscribe();
bus.destroy(); // on app teardown

Events emitted in one browser tab are delivered to every other same-origin tab automatically — no polling, no server round-trip.

Telling local events apart from cross-tab events

Every Dispatcher instance has its own sourceId (auto-generated, overridable via new Dispatcher({ sourceId })). It travels with every envelope the instance emits and is handed to every listener as a second, optional meta argument - never merged into the payload:

bus.on('auth:login', (payload, meta) => {
  meta.sourceId; // which Dispatcher instance originally emitted this
  meta.isSelf;   // true for this instance's own emit(), false if it
                 // arrived via a transport from another tab/process
  meta.timestamp;
});

Handlers that only declare payload keep working unchanged - meta is purely additive.

API

bus.sourceId                        // this Dispatcher instance's unique id
bus.on(event, handler)              // -> Unsubscribe, registration-scoped
                                     //    handler(payload, meta) - meta.sourceId / meta.isSelf
bus.once(event, handler)            // -> Unsubscribe, fires once
bus.off(event, handler)             // reference-based removal (Node/DOM semantics)
bus.emit(event, payload)            // -> boolean, true if anyone was listening
bus.destroy()

Dispatcher is intentionally minimal: registration (on/once), removal (off), and emission (emit), plus destroy() for teardown. Listener introspection, wildcard subscriptions, and promise-based waiting are not part of the core API - see docs/audit.md for the reasoning.

See docs/audit.md for the reasoning behind on() vs off()'s different unsubscribe semantics before relying on off() with a reused handler reference.

Using more than one localStoragePrefix

If you run multiple independent buses in the same origin, give each a prefix that isn't a prefix of another (matching is startsWith): "app:" and "app:v2:" will cross-talk, but "app:v1:" and "app:v2:" won't.

Compatibility

| Environment | Support | |---|---| | Modern evergreen browsers (Chrome, Firefox, Edge) | Full - both transports work | | Safari ≥ 15.4 | Full | | Safari < 15.4 | BroadcastChannel unsupported - falls back to LocalStorageTransport automatically (feature-detected) | | Safari Private Browsing | localStorage.setItem throws - writes are swallowed; cross-tab sync silently degrades to same-tab-only, local emit/on still work | | Node.js ≥ 18 (SSR) | Safe to import; both transports no-op until isBrowser() is true |

This package is published as ESM only ("type": "module", no CJS require() build). Every environment above, and every modern bundler, supports import natively; if you need require('@event-kit/bus'), pin to 0.1.x.

Design notes

  • Bounded memory under load. The dispatcher's de-duplication cache is capped by both a time window (dedupWindowMs) and a hard entry count (maxDedupEntries), so a message flood can't grow memory unboundedly.
  • Untrusted input is validated. Anything arriving from localStorage or postMessage is run through a structural guard (isEnvelopeLike) before being trusted, since both are same-origin channels other scripts/extensions can also write to.
  • Handler and transport errors are isolated. A throwing listener or a throwing transport.send never breaks other listeners/transports or crashes emit(); errors are routed to a configurable onError sink.
  • SSR-safe. Every browser API access is guarded by isBrowser(), so importing the package during server-side rendering never throws.
  • No runtime dependencies. Fully auditable, small bundle footprint, sideEffects: false for clean tree-shaking.
  • ESM only. No CJS require() build - see Compatibility above.
  • sourceId is cheap. One string per Dispatcher instance, stamped onto every envelope it emits; computing meta.isSelf on delivery is a single string comparison, not a new allocation per listener.