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

@alwatr/page-ready

v9.24.0

Published

Lightweight page identity signal for MPA routing — reads page-id attribute and notifies subscribers.

Readme

@alwatr/page-ready

Lightweight page identity signal for multi page applications routing.

Reads the page-id HTML attribute from the document and notifies subscribers using a dedicated O(1) channel signal. Designed for SSG/SSR setups where each generated page has a different page-id baked into the HTML.


Why @alwatr/page-ready?

In SSG/SSR apps, the server renders a different HTML page for each route. Each page has a page-id attribute somewhere in the document. Instead of a full client-side router, you just need to know which page is currently loaded so you can run page-specific initialization logic.

@alwatr/page-ready solves exactly this — nothing more.


Installation

bun add @alwatr/page-ready
# or
npm i @alwatr/page-ready

Quick Start

1. Add page-id to your HTML

<!-- Each SSG-generated page has a unique page-id — can be on any element -->
<body page-id="home">
  …
</body>

2. Subscribe and dispatch

import {onPageReady, subscribePageReady, dispatchPageReady} from '@alwatr/page-ready';

// Optionally constrain valid page IDs with a type alias
type PageId = 'home' | 'about' | 'product-detail';

// Subscribe to a specific page
onPageReady<PageId>('home', () => initHomePage());
onPageReady<PageId>('about', () => initAboutPage());

// Or subscribe to ALL pages and receive the page ID in the handler
subscribePageReady<PageId>((pageId) => {
  console.log('Page ready:', pageId);
  analytics.trackPageView(pageId);
});

// Call once at bootstrap — finds [page-id] anywhere in the document and notifies subscribers
dispatchPageReady();

How It Works

dispatchPageReady()
  │
  └─ document.querySelector('[page-id]').getAttribute('page-id') → 'home'
       │
       └─ pageReadyChannel_.dispatch('home')
            │
            ├─ Map.get('home') → O(1) → invoke only 'home' handlers  (onPageReady)
            └─ global subscribers → invoked for every page ID         (subscribePageReady)
  • dispatchPageReady scans the entire document for the first [page-id] element — no argument needed.
  • ChannelSignal routes in O(1): onPageReady handlers for non-matching page IDs are never invoked.
  • subscribePageReady handlers receive the dispatched page ID and are called on every dispatch.

API Reference

onPageReady(pageId, handler)

Subscribes to a specific page becoming ready. The handler is only invoked when the dispatched page ID matches pageId.

function onPageReady<T extends string>(pageId: T, handler: () => Awaitable<void>): SubscribeResult;

Pass a string literal union as the generic to constrain valid page IDs:

type PageId = 'home' | 'about' | 'product-detail';

const sub = onPageReady<PageId>('home', () => initHomePage());
sub.unsubscribe(); // stop listening when no longer needed

subscribePageReady(handler)

Subscribes to all page-ready events. The handler is invoked on every dispatchPageReady() call, regardless of which page ID is dispatched. The current page ID is passed as the first argument.

function subscribePageReady<T extends string>(handler: (pageId: T) => Awaitable<void>): SubscribeResult;

Useful for cross-cutting concerns like analytics, logging, or layout transitions that need to react to every page change:

type PageId = 'home' | 'about' | 'product-detail';

const sub = subscribePageReady<PageId>((pageId) => {
  analytics.trackPageView(pageId);
  updateActiveNavLink(pageId);
});

sub.unsubscribe(); // stop listening when no longer needed

dispatchPageReady()

Finds the first [page-id] element anywhere in the document and notifies all matching subscribers.

function dispatchPageReady(): void;

Call once at application bootstrap. Logs an accident if no [page-id] element is found in the document. An empty attribute value (page-id="") is treated as a valid identifier and dispatched normally.

The lookup uses document.querySelector('[page-id]'), so the attribute can be placed on any element (<body>, <main>, <div>, etc.).


Choosing Between onPageReady and subscribePageReady

| Use case | API | | ------------------------------------------- | -------------------- | | Initialize logic for one specific page | onPageReady | | React to every page change (analytics, nav) | subscribePageReady | | Multiple pages, each with their own init | onPageReady × N | | Single handler that branches on the page ID | subscribePageReady |



🌊 Part of Alwatr Flux

@alwatr/page-ready is the Routing Layer of the Alwatr Flux architecture — a complete Unidirectional Data Flow system for building scalable Progressive Web Applications.

In the Flux architecture, @alwatr/page-ready handles page identity for Multi-Page Applications (MPA). It reads the page-id attribute from the HTML and notifies the application which page is currently active — enabling page-specific initialization without a full client-side router.

// Use @alwatr/flux for the complete architecture
import {onPageReady, subscribePageReady, dispatchPageReady, setupActionDelegation} from '@alwatr/flux';

// Or use @alwatr/page-ready standalone
import {onPageReady, subscribePageReady, dispatchPageReady} from '@alwatr/page-ready';

View the complete Flux documentation


Contributing

Contributions are welcome! Please read our contribution guidelines before submitting a pull request.

License

MPL-2.0 — see LICENSE.