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

netlytics

v0.3.0

Published

Reliable internet connectivity, latency, and connection type for web apps. Works across WiFi, mobile data, and frameworks.

Readme

Introduction

A lightweight library for detecting internet connectivity, measuring latency, and identifying connection types (WiFi, mobile data, ethernet) in web applications. Built to fix the common problem where libraries report "not connected" even when the user is online.

Netlytics validates connectivity with real HTTP probes instead of relying on unreliable browser APIs. It works consistently across WiFi and mobile data, providing accurate status updates for your users.

Why

Many NPM connectivity libraries give wrong results:

  • Relying only on navigator.onLine (true when on any network, even without internet)
  • Single-endpoint checks that fail due to CORS, CDN issues, or that one URL being down
  • No distinction between WiFi and mobile data, or bad behavior when switching networks

We believe connectivity detection should be reliable and accurate. Netlytics uses multiple probe URLs, configurable timeouts, and validates both online and offline events with real network requests — never trusting navigator.onLine alone.

Install

Install Netlytics from your command line.

With bun

bun add netlytics

With npm

npm install netlytics

With pnpm

pnpm add netlytics

With yarn

yarn add netlytics

Getting started

Import the functions you need and start checking connectivity.

import {
  checkConnectivity,
  getConnectionType,
  measureLatency,
  watchConnectivity,
} from "netlytics";

// Check if the user is actually online (probe-based, not just navigator.onLine)
const result = await checkConnectivity();
console.log(result.online); // true | false
console.log(result.connectionType); // "wifi" | "cellular" | "unknown" | ...
console.log(result.latencyMs); // optional RTT from probe

// Get connection type hint (when supported by browser)
const type = getConnectionType(); // "wifi" | "cellular" | "ethernet" | "unknown"

// Measure latency in ms
const latency = await measureLatency();
console.log(latency); // number | null

// Live updates: both "online" and "offline" events are validated with a probe
const unsubscribe = watchConnectivity(
  (result) => {
    console.log(result.online ? "Connected" : "Disconnected");
  },
  { observe: true } // default; set observe: false to disable
);
// later: unsubscribe();

API

A set of functions to help you build reliable connectivity detection without dealing with browser inconsistencies.

checkConnectivity(options?)

Checks if the device has reachable internet by probing one or more URLs. Returns Promise<ConnectivityResult>:

  • online: boolean — Internet reachable (at least one probe succeeded)
  • connectionType: ConnectionType — Best-effort: "wifi" | "cellular" | "ethernet" | "none" | "unknown"
  • networkQuality: NetworkQuality — Best-effort: "slow-2g" | "2g" | "3g" | "4g" | "unknown"
  • latencyMs?: number — RTT of the first successful probe

Options:

  • timeout — Timeout in ms per probe (default: 5000)
  • requiredSuccesses — How many probes must succeed (default: 1)
  • probeUrls — Custom URLs (must support CORS)

getConnectionType()

Returns ConnectionType from the Network Information API when available. Use for UX only; do not use as the only check for online/offline.

getNetworkQuality()

Returns NetworkQuality from the Network Information API when available. Represents connection speed/quality (slow-2g, 2g, 3g, 4g).

measureLatency(options?)

Measures round-trip time (latency) in ms by sampling requests to a reliable endpoint. Returns Promise<number | null> — average RTT in ms, or null if all samples failed.

Options:

  • timeout — Timeout per request (default: 5000)
  • sampleSize — Number of samples (default: 3)

watchConnectivity(callback, options?)

Subscribes to online / offline events and validates each with a network probe (never relies only on navigator.onLine). Returns an unsubscribe() function.

Options (all optional):

  • observe — When true (default), listen and validate. When false, no listeners (manual checks only).
  • debounceMs — Delay before probing after an "online" event (default: 400).
  • offlineProbeTimeoutMs — Timeout when validating an "offline" event (default: 2000).
  • onChecking — Called when a probe is about to run (e.g. to show "Checking…").
  • Plus all ConnectivityOptions (timeout, probeUrls, etc.).

Try it

A live demo is available to test Netlytics in the browser before installing:

  • Demo (Vercel) — See connectivity detection, connection type, and latency in real time

Support

Netlytics works with all popular JavaScript frameworks and vanilla JavaScript:

| | | | | | | ------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | React ✔ | Vue ✔ | Angular ✔ | Svelte ✔ | Vanilla JS ✔ |

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Security

To report a security vulnerability, please see SECURITY.md.

License

MIT License - see LICENSE file for details.