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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@snps/message-bus

v0.0.2

Published

Zero-dependency message bus system for decoupled communication

Readme

@snps/message-bus

Zero-dependency message bus system for decoupled, event-driven communication.

Installation

pnpm install @snps/message-bus

API

MessageBus

The MessageBus class provides a central communication hub for publishing and subscribing to messages.

publish<T>(type: string, payload: T, options?: PublishOptions)

Publishes a message to the bus.

import { MessageBus } from '@snps/message-bus';

const bus = new MessageBus();
bus.publish('user.created', { id: 1, name: 'John Doe' });

subscribe<T>(pattern: string, handler: MessageHandler<T>, options?: SubscribeOptions)

Subscribes to messages of a specific type or pattern.

import { MessageBus } from '@snps/message-bus';

const bus = new MessageBus();
const unsubscribe = bus.subscribe('user.created', (payload) => {
  console.log('User created:', payload);
});

request<T, R>(type: string, payload: T, timeout?: number)

Publishes a message and waits for a response.

import { MessageBus } from '@snps/message-bus';

const bus = new MessageBus();
const response = await bus.request('question', { question: 'What is the meaning of life?' });

respond<T>(message: Message, payload: T)

Responds to a request.

import { MessageBus } from '@snps/message-bus';

const bus = new MessageBus();
bus.subscribe('question', (payload, message) => {
  bus.respond(message, { answer: 42 });
});

use(middleware: Middleware)

Adds middleware for message processing.

import { MessageBus } from '@snps/message-bus';

const bus = new MessageBus();
bus.use((message, next) => {
  console.log('Middleware:', message.type);
  next();
});

getDeadLetterQueue(): Message[]

Gets the dead letter queue (failed messages).

const deadLetterQueue = bus.getDeadLetterQueue();

getHistory(): Message[]

Gets the message history.

const history = bus.getHistory();

replay(messageId: string)

Replays a message from history.

bus.replay('msg_123');

clear()

Clears all subscriptions and queues.

bus.clear();

getStats()

Gets statistics about the message bus.

const stats = bus.getStats();

getGlobalBus(): MessageBus

Provides a global singleton bus instance.

import { getGlobalBus } from '@snps/message-bus';

const globalBus = getGlobalBus();

resetGlobalBus()

Resets the global bus instance.

import { resetGlobalBus } from '@snps/message-bus';

resetGlobalBus();

createPublisher<T>(bus: MessageBus, type: string)

Utility to create a typed publisher.

import { MessageBus, createPublisher } from '@snps/message-bus';

const bus = new MessageBus();
const publishUserCreated = createPublisher<{ id: number, name: string }>(bus, 'user.created');
publishUserCreated({ id: 1, name: 'John Doe' });

createSubscriber<T>(bus: MessageBus, type: string, handler: MessageHandler<T>, options?: SubscribeOptions)

Utility to create a typed subscriber.

import { MessageBus, createSubscriber } from '@snps/message-bus';

const bus = new MessageBus();
const unsubscribe = createSubscriber<{ id: number, name: string }>(bus, 'user.created', (payload) => {
  console.log('User created:', payload);
});

createRequestHandler<T, R>(bus: MessageBus, type: string, handler: (payload: T, message: Message<T>) => R | Promise<R>)

Utility to create a request handler.

import { MessageBus, createRequestHandler } from '@snps/message-bus';

const bus = new MessageBus();
createRequestHandler<{ question: string }, { answer: number }>(bus, 'question', (payload) => {
  return { answer: 42 };
});