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

@bazariodev/net-monitor

v0.2.0

Published

Dependency-free browser network state observation.

Readme

@bazariodev/net-monitor

BrowserNetMonitor reports the browser's online and offline hints. It has no dependencies and does not start observation until the first subscriber.

Install

pnpm add @bazariodev/net-monitor

Usage

import { BrowserNetMonitor } from '@bazariodev/net-monitor';

const monitor = new BrowserNetMonitor();
const unsubscribe = monitor.subscribe((state) => {
  console.log(`Browser network state: ${state}`);
});

The application owns monitor. Call unsubscribe() to remove one listener. Call monitor.stop() when the application no longer needs the monitor.

Behavior

  • getSnapshot() returns online or offline.
  • Without subscribers, getSnapshot() reads navigator.onLine. With subscribers, it returns the last observed state. A missing or non-boolean value causes a TypeError when the monitor reads it.
  • A startup sample of navigator.onLine === false reports offline before any event.
  • The first subscription adds browser online and offline listeners. The last unsubscribe removes them. A later subscription reads the platform state again.
  • Each call to subscribe() has its own cleanup function, including calls with the same listener.
  • Repeated states do not notify listeners. A listener error does not stop other listeners.
  • stop() is permanent. It removes listeners, keeps the last snapshot, and makes later subscriptions inactive.
  • Browser online state is a hint. It does not confirm that a server is reachable.

API

| API | Behavior | | --- | --- | | new BrowserNetMonitor(options?) | Create a monitor. Construction adds no browser listeners. | | getSnapshot() | Read the current state without subscribing. | | subscribe(listener) | Listen for state changes. Return an idempotent unsubscribe function. | | stop() / [Symbol.dispose]() | Remove all listeners and stop the monitor permanently. |

BrowserNetMonitorOptions.platform selects a platform port for tests or another host. It must provide a boolean navigator.onLine value. It may also provide addEventListener and removeEventListener. onListenerError receives errors from listeners and platform listener removal. Errors from listener attachment are thrown after the monitor releases any listener that it already added.

The source also implements this structural interface:

type ConnectivityState = 'online' | 'offline';

interface ConnectivitySource {
  getSnapshot(): ConnectivityState;
  subscribe(listener: (state: ConnectivityState) => void): () => void;
}

Errors

getSnapshot() and subscribe() throw TypeError when a platform read does not return a boolean. subscribe() also throws TypeError when its listener is not a function. The monitor releases a new registration if its sample fails. A platform error while adding a browser listener is thrown after partial setup is released. Errors from navigator or onLine accessors pass through unchanged. Listener errors go to onListenerError; if that callback throws, the monitor contains that error.

TypeScript

The declarations use no DOM types. The platform option uses small structural types, so the package can type-check in Node, browser, and worker projects.

License

MIT — see LICENSE.