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

@zvoove/broadcast-channels

v1.2.0

Published

Shared Broadcast Channel messaging contract for PDL micro-frontend architecture

Readme

@zvoove/broadcast-channels

Typed, validated event bus for the PDL micro-frontend architecture. Provides safe, structured communication between the Shell app and fragment applications over the browser's native BroadcastChannel API.

Installation

pnpm add @zvoove/broadcast-channels

or

npm add @zvoove/broadcast-channels

Two-channel model

Communication is split into two directional channels:

| Channel | Name | Direction | Events | | ---------------- | ------------------ | ------------------------- | ------------------------------------- | | Shell channel | pdl:shell | Shell → Fragments | AUTH_CHANGED, THEME_CHANGED | | Fragment channel | pdl:{fragmentId} | Fragment → Shell / Others | FRAGMENT_READY, BREADCRUMB_UPDATE |

Shell app

import {
  type AuthUser,
  CONTRACT_VERSION,
  createFragmentChannel,
  createShellChannel,
  onVersionMismatch,
} from '@zvoove/broadcast-channels';

// ── Outbound: emit state changes to all fragments ──────────────────────────
const shell = createShellChannel();

function onLogin(user: AuthUser) {
  shell.emit('AUTH_CHANGED', { user });
}
function onLogout() {
  shell.emit('AUTH_CHANGED', { user: null });
}
function onThemeChange(theme: 'light' | 'dark') {
  shell.emit('THEME_CHANGED', { theme });
}

// ── Inbound: listen to a specific fragment ─────────────────────────────────
const zain = createFragmentChannel('zain');

zain.on('BREADCRUMB_UPDATE', ({ items }) => {
  updateBreadcrumbs(items); // items is BreadcrumbItem[], compatible with unity-ui
});

onVersionMismatch(zain, CONTRACT_VERSION, (fragmentId, version) => {
  console.warn(`Fragment "${fragmentId}" is on contract v${version} — reload may be required`);
});

// ── Cleanup ────────────────────────────────────────────────────────────────
shell.destroy();
zain.destroy();

Fragment app (e.g. zain)

import {
  type BreadcrumbItem,
  type Unsubscribe,
  announceFragment,
  createFragmentChannel,
  createShellChannel,
} from '@zvoove/broadcast-channels';

const shell = createShellChannel();
const frag = createFragmentChannel('zain');
const subscriptions: Unsubscribe[] = [];

// ── On mount ───────────────────────────────────────────────────────────────
subscriptions.push(
  shell.on('AUTH_CHANGED', ({ user }) => {
    if (user === null) return clearAuth();
    setAuth(user); // user is typed as AuthUser
  }),
  shell.on('THEME_CHANGED', ({ theme }) => {
    document.documentElement.dataset.theme = theme;
  }),
);

announceFragment(frag, 'zain'); // emits FRAGMENT_READY with CONTRACT_VERSION

// ── On route change ────────────────────────────────────────────────────────
function onRouteChange(items: BreadcrumbItem[]) {
  frag.emit('BREADCRUMB_UPDATE', { items });
}

// ── On unmount ─────────────────────────────────────────────────────────────
subscriptions.forEach((u) => u());
shell.destroy();
frag.destroy();

Event types

Shell events (pdl:shell)

type ShellEvent =
  | { type: 'AUTH_CHANGED'; payload: { user: AuthUser | null } }
  | { type: 'THEME_CHANGED'; payload: { theme: 'light' | 'dark' } };

interface AuthUser {
  id: string;
  name: string;
  email: string;
  role: string;
  department: string;
}

Fragment events (pdl:{fragmentId})

type FragmentEvent =
  | { type: 'FRAGMENT_READY'; payload: { fragmentId: string; version: string } }
  | { type: 'BREADCRUMB_UPDATE'; payload: { items: BreadcrumbItem[] } };

// BreadcrumbItem is structurally compatible with BreadcrumbsItem from @zvoove/unity-ui
type BreadcrumbItem = { label: string; href: string };

API reference

| Function | Returns | Description | | ----------------------------------------- | ----------------------------- | --------------------------------------------------------- | | createShellChannel(options?) | TypedChannel<ShellEvent> | Channel on pdl:shell. Shell emits; fragments subscribe. | | createFragmentChannel(id, options?) | TypedChannel<FragmentEvent> | Channel on pdl:{id}. Fragment emits; shell subscribes. | | fragmentChannelName(id) | string | Returns pdl:{id}. | | announceFragment(channel, id, version?) | void | Emits FRAGMENT_READY with CONTRACT_VERSION (default). | | onVersionMismatch(channel, version, cb) | Unsubscribe | Calls cb(fragmentId, actualVersion) on version skew. | | CHANNEL_NAMES | { SHELL: 'pdl:shell' } | Shell channel name constant. | | CONTRACT_VERSION | string | Runtime contract version for the version handshake. |

Development

pnpm install
pnpm build          # ESM + CJS + .d.ts
pnpm test           # Vitest
pnpm test:watch     # Vitest watch mode
pnpm lint           # ESLint
pnpm format         # Prettier
pnpm docs           # TypeDoc → docs/api-reference/

See CONTRIBUTING.md for architecture details, how to add events, and the release process.