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

@worldhacker/service-health-badge

v0.12.4

Published

Embedded service health badge Web Component (<service-health-badge>)

Downloads

6

Readme

English | Русский: see docs ENRU

Minimal, framework‑free Web Component for displaying service status via GET /health. Lightweight, accessible, themeable, and i18n‑friendly.

  • Zero deps, ESM, tree‑shakable
  • Three UI variants: dotchipbadge
  • Emits health-change and health-error
  • Debounced visual updates, background optimizations
  • A11y‑ready: role=status, aria-live=polite, forced‑colors support

Table of Contents

Quick Start

Docs: ENRU

Add the script and the element with your endpoint:

<script
  type="module"
  src="https://cdn.jsdelivr.net/npm/@worldhacker/service-health-badge/dist/service-health-badge.js"
></script>

<service-health-badge
  endpoint="https://api.example.com/health"
  variant="badge"
  degraded-threshold-ms="150"
></service-health-badge>

Install

Docs: ENRU

  • npm: npm i @worldhacker/service-health-badge
  • pnpm: pnpm add @worldhacker/service-health-badge
  • yarn: yarn add @worldhacker/service-health-badge

Import in your app:

import '@worldhacker/service-health-badge';

Via CDN (ESM):

<script
  type="module"
  src="https://cdn.jsdelivr.net/npm/@worldhacker/service-health-badge/dist/service-health-badge.js"
></script>

Usage

Docs: ENRU

Minimal example:

<service-health-badge endpoint="/health"></service-health-badge>

Full example with params and i18n:

<service-health-badge
  endpoint="/health"
  interval="10000"
  timeout="3000"
  variant="badge"
  degraded-threshold-ms="200"
  labels='{"ok":"OK","degraded":"Slow","down":"Down","unknown":"—","offline":"Offline"}'
></service-health-badge>

JS API (props/methods):

const el = document.querySelector('service-health-badge');
el.interval = 8000;
el.timeout = 2500;
el.showLatency = true;
el.degradedThresholdMs = 150;
el.labels = { degraded: 'Reduced' };
await el.refresh();

Attributes and Properties

Docs: ENRU

  • endpoint: string — GET /health endpoint (required to poll).
  • interval: number (ms), default 10000 — polling period.
  • timeout: number (ms), default 3000 — request timeout.
  • labels: JSON, merged with defaults — localized labels.
  • variant: dot | chip | badge (default badge).
  • show-latency: set false to hide latency in badge.
  • degraded-threshold-ms: number (ms). If base is ok and latency > threshold → render degraded.
  • focusable: when present, element is keyboard focusable.
  • dev-state: force a state for local dev (unknown|ok|degraded|down|offline).

Available statuses: unknown, ok, degraded, down, offline.

Methods:

  • refresh(): Promise<boolean> — poll immediately.
  • setState(status, latencyMs?) — set state manually (threshold still applies).

Events

Docs: ENRU

  • health-change — on effective status change. detail: { status, latencyMs, at }.
  • health-error — on network/timeout/JSON error. detail: { error }.

Example:

<service-health-badge id="hb" endpoint="/health"></service-health-badge>
<script>
  const el = document.getElementById('hb');
  el.addEventListener('health-change', (e) => {
    const { status, latencyMs } = e.detail;
    console.log('status =', status, 'latency =', latencyMs);
  });
  el.addEventListener('health-error', (e) => console.warn('health-error:', e.detail.error));
  // document.getElementById('btn').onclick = () => el.refresh();
</script>

Theming

Docs: ENRU • Variants ENRU

CSS custom properties are supported (global or per element):

  • --health-size: base font size (0.875rem)
  • --health-radius: border radius (0.5rem)
  • --health-color-fg: text color (currentColor)
  • --health-chip-bg: chip/badge background (rgba(0,0,0,0.05))
  • --health-bg-ok|degraded|down|unknown|offline: indicator colors
  • --health-focus-ring: focus ring color (optional)

React Integration

Docs: ENRU

Use the wrapper from examples/react/HealthBadge.tsx or create the element directly:

import React from 'react';
import '@worldhacker/service-health-badge';

export function HealthBadge(props: any) {
  return React.createElement('service-health-badge', props as any);
}

<HealthBadge endpoint="/health" variant="badge" degradedThresholdMs={150} />;

Backend and CORS

Docs: ENRU

Component expects JSON from GET /health. Minimal:

{ "status": "ok", "timings": { "total_ms": 23 } }

Local Demo

  • Start mock /health server: npm run mock → prints http://127.0.0.1:<port>
  • Preview static demo: npm run preview → open /demo/index.html

The demo UI lets you switch server vs. local fetch stub.

Browser Support

  • Modern browsers with Web Components (Custom Elements, Shadow DOM).
  • Polyfills are not bundled. Add CE/Shadow DOM polyfills if you target very old browsers.

License

MIT © 2025 — see LICENSE.