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

lite-trie-router

v1.0.0

Published

Ultra-light React router with O(M) trie matching, predictive preload, and useSyncExternalStore

Readme

lite-trie-router

Ultra-light React router (~2KB min+gzip) built for O(M) URL matching (M = path segments), predictive code-split preloading, and useSyncExternalStore history sync.

Why this router?

| Technique | Benefit | | ----------------------- | ---------------------------------------------------------------- | | Segment trie | Match cost grows with URL depth, not total route count | | Shared import cache | Hover prefetch and click navigation reuse one import() promise | | History patch | pushState / replaceState / popstate all notify React | | Manual path split | No regex on hot path; V8-friendly string scans | | startTransition | Route paint stays responsive during chunk resolution |

Install

npm install lite-trie-router

Peer dependency: React 18+.

Quick start

import { CustomRouter, Link, useParams, useQuery } from "lite-trie-router";

const routes = [
  { path: "/", loadFn: () => import("./pages/Home.jsx") },
  { path: "/dashboard/:userId", loadFn: () => import("./pages/Dashboard.jsx") },
];

export default function App() {
  return (
    <CustomRouter
      routes={routes}
      fallback={<div>404</div>}
      loadingFallback={<div>Loading…</div>}
    >
      <nav>
        <Link to="/dashboard/abc?tab=metrics">Dashboard</Link>
      </nav>
    </CustomRouter>
  );
}

function DashboardPage() {
  const { userId } = useParams();
  const { tab } = useQuery();
  return (
    <h1>
      {userId} — {tab}
    </h1>
  );
}

Note: Place <Link> inside <CustomRouter> so prefetch can access the compiled trie.

API

Components

  • CustomRouter{ routes, fallback, loadingFallback?, children? }
  • Link{ to, prefetch?, ...anchorProps } — preloads on mouseenter, focus, and touchstart

Hooks

  • useParams() — dynamic segments (:id{ id: '42' })
  • useQuery() — parsed query object
  • useHash() — hash without #
  • useLocation(){ pathname, search, hash }

Imperative

import { navigate } from "lite-trie-router";

navigate("/settings", { replace: true });

Low-level (testing / custom integrations)

  • createTrieRouter(routes)
  • matchTrie(root, pathname, segments?)
  • parseUrl(url)
  • splitPath(pathname)
  • prefetchRoute(routeKey, loadFn)
  • clearRouteCache()

Performance tips

  1. Use stable routes array reference (or memoize) to avoid rebuilding the trie.
  2. Keep loadFn as () => import('./Page') — the library dedupes by route path.
  3. Disable prefetch on huge menus: <Link prefetch={false} />.
  4. Run npm run bench locally — reports match-only (cached segments) vs split+match.
  5. High fanout nodes (48+ sibling routes) auto-switch to Map lookups at compile time.

License

MIT