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

@magnet-js/router

v0.1.2

Published

Signal-based routing for Magnet applications.

Readme

@magnet/router

Signal-based routing for Magnet applications.

@magnet/router provides a minimal, composable routing core built on signals. Routes are plain functions evaluated in registration order; the first non-undefined result wins. No JSX, no route objects, no outlets — just functions and arrays.

Install

JSR

deno add jsr:@magnet/router

npm via JSR

npx jsr add @magnet/router

npm

npm install @magnet-js/router

Usage

Basic routing

import { router } from "@magnet/router";
import { tc39 } from "@magnet/signal";

const routes = [
  (l: URL) => l.pathname === "/" ? "Home" : undefined,
  (l: URL) => l.pathname === "/about" ? "About" : undefined,
];

const r = router(tc39)(routes)(location);

Path parameters

import { match, router } from "@magnet/router";

const routes = [
  (l: URL) => {
    const params = match(l.pathname, "/users/:id");
    return params ? `User ${params.id}` : undefined;
  },
];

Search parameters

import { query, SearchTransform } from "@magnet/router";

const params = query({ page: SearchTransform.First })(location.search);
// ?page=1&page=2 → { page: "1" }

Guards

Guards wrap a route handler and block it when a check fails. The check can read any external state, not just the location:

import { guard, router } from "@magnet/router";
import { tc39 } from "@magnet/signal";

const user = tc39.state<string | null>(null);

const authenticated = guard(() => user.get() !== null);

const routes = [
  (l: URL) => l.pathname === "/login" ? "Login" : undefined,
  authenticated((l: URL) => l.pathname === "/profile" ? "Profile" : undefined),
];

When user is null, the /profile route falls through to the next registered route (or the fallback).

Browser history

import { historian } from "@magnet/router";

const h = historian(tc39, window, {
  restoreScroll: true,
  focusTarget: "main",
})();

Async routes

import { lazy } from "@magnet/common";
import { router } from "@magnet/router";

const routes = [
  (l: URL) =>
    l.pathname === "/heavy"
      ? lazy(tc39, () => import("./heavy.ts"), "Loading…")
      : undefined,
];

Accessibility announcer

import { announcer } from "@magnet/router";
import { magnet } from "@magnet/ui";

const m = magnet({ window, ...tc39 });
const el = announcer(m, location, (l) => `Navigated to ${l.pathname}`);

Public API

  • router — creates a computed router signal from a route array and location.
  • historian — creates a history adapter for browser or server.
  • match — parses path patterns with :param and * wildcards.
  • query — parses URL search strings with per-key transformers.
  • guard — wraps a route handler with a location check.
  • announcer — creates an ARIA live region for screen reader announcements.
  • Route / Router — route handler and router signal types.
  • MagnetHistory / MagnetLocation — history adapter and location types.
  • Historian / HistorianOptions — history factory and options.
  • LocationTransformer — custom location shape transformer.
  • SearchTransform — enum for common search value combinations.

License

MIT © 2026 Fernando G. Vilar.