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

alevent

v1.0.3

Published

`alevent` is a **lightweight and flexible event bus library** for handling communication between different parts of your application. It supports two modes of event-driven communication:

Readme

alevent - A Lightweight Event Bus for JavaScript & TypeScript

alevent is a lightweight and flexible event bus library for handling communication between different parts of your application. It supports two modes of event-driven communication:

  • AppEventBus: For applications that exist on the same domain and are bundled together at build time (e.g., widgets, micro-frontends within a single app).
  • GlobalEventBus: For applications that exist on different domains (e.g., iframes, cross-origin communication).

🚀 Installation

npm install alevent

🔹 Usage

1️⃣ Using AppEventBus for Same-Domain Communication

Use AppEventBus when components, widgets, or micro-frontends exist within the same domain and can communicate directly in memory.

📌 Example: Communication Between Widgets

import { AppEventBus } from 'alevent';

// Create an instance of AppEventBus
const appBus = new AppEventBus<string>();

// Widget A: Subscribe to an event
appBus.on('userLoggedIn', (username) => {
  console.log(`User logged in: ${username}`);
});

// Widget B: Emit an event
appBus.emit('userLoggedIn', 'Alice');

Fast and efficient – Uses in-memory communication. ✅ Ideal for single-page applications (SPAs), widgets, and modules.


2️⃣ Using GlobalEventBus for Cross-Domain Communication

Use GlobalEventBus when applications reside on different domains (e.g., a parent app communicating with an iframe).

📌 Example: Communication Between a Parent App and an Iframe

import { GlobalEventBus } from 'alevent';

// Parent App: Emit an event
const globalBus = new GlobalEventBus<string>();
globalBus.emit('iframeMessage', 'Hello from Parent');

// Iframe App: Listen for the event
const iframeBus = new GlobalEventBus<string>();
iframeBus.on('iframeMessage', (message) => {
  console.log(`Received in iframe: ${message}`);
});

Allows cross-origin communication (e.g., between an iframe and its parent page).
Uses window.dispatchEvent for event propagation.


🔹 Propagation Control and Ordered Handlers

Both AppEventBus and GlobalEventBus support ordered handlers and stopping propagation. A listener can prevent further handlers from executing by returning false.

📌 Example: Ordered Handlers and Stopping Propagation

import { AppEventBus } from 'alevent';

const appBus = new AppEventBus<string>();

appBus.on('message', (msg) => {
  console.log(`[Handler 1] Received: ${msg}`);
  return true; // Continue propagation
}, 0);

appBus.on('message', (msg) => {
  console.log(`[Handler 2] Processing: ${msg}`);
  return false; // Stop propagation
}, 1);

appBus.on('message', (msg) => {
  console.log(`[Handler 3] Should not run`);
}, 2);

appBus.emit('message', 'Hello!');

Handlers execute in order (by index).
Propagation stops when a handler returns false.


📌 Features

  • 🚀 Supports Ordered Handlers – Event handlers execute in the order they were added.
  • 🛑 Propagation Control – Listeners can stop event propagation by returning false.
  • 🏗 Lightweight & Fast – Optimized for minimal performance overhead.
  • 🔄 Supports Dynamic Subscription & Removal – Easily add or remove event listeners at runtime.

✅ API Reference

1. AppEventBus (For Same-Domain Communication)

🔹 on(event: string, listener: (data: T) => boolean | void, index?: number): void

Registers an event listener with an optional order index.

🔹 off(event: string, listener: (data: T) => boolean | void): void

Removes an event listener.

🔹 emit(event: string, data: T): void

Emits an event, triggering all subscribed listeners.

2. GlobalEventBus (For Cross-Domain Communication)

🔹 on(event: string, listener: (data: T) => boolean | void, index?: number): void

Registers an event listener on the window object.

🔹 off(event: string, listener: (data: T) => boolean | void): void

Removes an event listener from the window object.

🔹 emit(event: string, data: T): void

Emits an event using window.dispatchEvent.


🔧 Development & Testing

Run tests to ensure functionality:

npm test

Build the package:

npm run build