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

@stephansama/typed-events

v3.0.5

Published

Typed events store using standard schema

Readme

@stephansama/typed-events

Source code Documentation NPM Version npm downloads

Typed events store using standard schema

Table of contents

Installation

pnpm install @stephansama/typed-events

Usage

createEvent

create a typed CustomEvent using a standard-schema compatible validator

import { createEvent } from "@stephansama/typed-events";

export const customAnimationEvent = createEvent(
  "custom-animation-event",
  z.object({
    x: z.number(),
    y: z.number(),
  }),
);

somewhere in your codebase

export function listenForAnimationEvent() {
  const item = document.getElementById("item");

  const cleanup = customAnimationEvent.listen((event) => {
    item.style.x = event.data.x;
    item.style.y = event.data.y;
  });

  return () => cleanup();
}

somewhere else in your codebase

export function dispatchEvent() {
  const x = document.getElementById("x");
  const y = document.getElementById("y");

  const button = document.getElementById("button");

  button.addEventListener("click", () => {
    customAnimationEvent.dispatch({
      x: +x.innerText,
      y: +y.innerText,
    });
  });
}

createEventMap

import { createEventMap } from "@stephansama/typed-events";

export const eventMap = createEventMap("event-map", {
  reset: z.object({}),
  update: z.object({ value: z.number() }),
});

somewhere in your codebase

export function listenForEventMap() {
  const value = document.getElementById("value");

  const cleanup = eventMap.listen("update", (message) => {
    value.textContent = message.data.value;
  });

  return () => cleanup();
}

somewhere else in your codebase

export function dispatchEventMap() {
  const button = document.getElementById("button");

  button.addEventListener("click", () => {
    eventMap.dispatch("update", {
      value: Math.floor(Math.random() * 100),
    });
  });
}

createBroadcastChannel

create a typed BroadcastChannel using a standard-schema compatible validator

import { createBroadcastChannel } from "@stephansama/typed-events";

export const channel = createBroadcastChannel("broadcaster", {
  reset: z.object({}),
  update: z.object({ value: z.number() }),
});

somewhere in your codebase

export function listenForChannelMessage() {
  const value = document.getElementById("value");

  const cleanup = channel.listen("update", (message) => {
    value.textContent = message.data.value;
  });

  return () => cleanup();
}

somewhere else in your codebase

export function dispatchChannelMessage() {
  const button = document.getElementById("button");

  button.addEventListener("click", () => {
    channel.dispatch("update", {
      value: Math.floor(Math.random() * 100),
    });
  });
}

createBroadcastEvent

create a typed BroadcastChannel and CustomEvent using a standard-schema compatible validator

import { createBroadcastEvent } from "@stephansama/typed-events";

export const broadcastEvent = createBroadcastEvent("broadcaster", {
  reset: z.object({}),
  update: z.object({ value: z.number() }),
});

somewhere in your codebase

export function listenForBroadcastEvent() {
  const value = document.getElementById("value");

  const cleanup = broadcastEvent.listen("update", (message) => {
    value.textContent = message.data.value;
  });

  return () => cleanup();
}

somewhere else in your codebase

export function dispatchBroadcastEvent() {
  const button = document.getElementById("button");

  button.addEventListener("click", () => {
    broadcastEvent.dispatch("update", {
      value: Math.floor(Math.random() * 100),
    });
  });
}

createMessage

create a typed MessageEvent using a standard-schema compatible validator

import { createMessage } from "@stephansama/typed-events";

export const message = createMessage("event-map", {
  reset: z.object({}),
  update: z.object({ value: z.number() }),
});

somewhere in your codebase

export function listenForMessage() {
  const value = document.getElementById("value");

  const cleanup = message.listen("update", (message) => {
    value.textContent = message.data.value;
  });

  return () => cleanup();
}

somewhere else in your codebase

export function dispatchMessage() {
  const button = document.getElementById("button");

  button.addEventListener("click", () => {
    message.dispatch("update", {
      value: Math.floor(Math.random() * 100),
    });
  });
}

React

you can use useListener or useListeners to automatically register and cleanup typed event listeners

import { useListeners } from "../dist/react.cjs";

const map = createBroadcastEvent("react-example", {
  first: z.object({}),
  second: z.object({ payload: z.number() }),
});

export function ExampleComponent() {
  useListeners(map, {
    first: () => console.info("first event happened"),
    second: ({ data }) => console.info(data.payload),
  });

  return; // more jsx...
}

References