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 🙏

© 2025 – Pkg Stats / Ryan Hefner

typesafe-routes

v12.1.0

Published

![minzipped size](https://badgen.net/bundlephobia/minzip/typesafe-routes@next) ![minified size](https://badgen.net/bundlephobia/min/typesafe-routes@next) ![tree shaking](https://badgen.net/bundlephobia/tree-shaking/typesafe-routes@next) [![discord link](h

Downloads

3,263

Readme

minzipped size minified size tree shaking discord link

Typesafe Routes

typesafe-routes helps you to accelerate your app development and reduce your test efforts by incorporating the TypeScript compiler for advanced type checking. Don't look for broken router paths manually; instead, let TypeScript notify you about inconsistencies in your routes.

typesafe-routes features include:

  • Autocompletion for paths and parameters
  • Path & template rendering
  • Nested, absolute, and relative path rendering
  • Parameter parsing and serialization
  • Type-safe, customizable, and extendable
  • Compatible with JavaScript (apart from type safety)
  • Small bundle size starting at less than 1kb

Example (Default Renderer)

import { createRoutes, int, renderPath, parsePath, template } from "typesafe-routes";

// route tree definition
const routes = createRoutes({
  users: {
    path: ["users", int("uid")],    // /users/:uid
    children: {
      edit: { path: ["edit"] },     // /users/:uid/edit
      delete: { path: ["delete"] }, // /users/:uid/delete
    }
  }
});

// absolute paths
renderPath(routes.users, { uid: 123 }); // ~> "/users/123"

// nested paths
renderPath(routes.users.edit, { uid: 123 }); // ~> "/users/123/edit"
renderPath(routes.users.delete, { uid: 123 }); // ~> "/users/123/delete"

// relative paths ("_" indicates the starting segment)
renderPath(routes._.users.$render, { uid: 123 }); // ~> "users/123"
renderPath(routes.users._.edit, {}); // ~> "edit"

// parse path params
parsePath(routes.users.edit, { uid: "42" }); // ~> { uid: 42 }
parsePath(routes.users.edit, "/users/99/edit"); // ~> { uid: 99 }

// templates 
template(routes.users.edit); // ~> "/users/:uid/edit"
template(routes._.users.edit); // ~> "users/:uid/edit"
template(routes.users._.edit); // ~> "edit"

Quick Reference

The complete documentation can be found here.

  • Functions
    • renderPath: renders a path with parameters
    • renderQuery: renders a search query
    • render: renders a path with parameters including query string
    • template: renders a route template
    • parsePath: parses dynamic segments in a path
    • parseQuery: parses parameters in a search query
    • parse: parses path and search query for parameters
    • replace: partially replaces dynamic segments and query params in a string-based path (i.e. location.path)

Installation

npm i typesafe-routes # or any npm alternative

How to Contribute

  • leave a star ⭐
  • report a bug 🐞
  • open a pull request 🏗️
    • please discuss your idea on github or discord before you start working on your PR
  • help others ❤️
  • buy me a coffee ☕

Roadmap

  • v10-v12 migration guide
  • v12beta-v12.1 migration guide
  • check for duplicate param names in the route tree
  • customizable parsing of search params (for example with qs)
  • demos & utils
    • react-router
    • wouter
    • vue router
    • angular router
    • refinejs

Docs

  • [x] quickstart
  • basic-features
    • [x] absolute-routes
    • [x] parameters
    • [x] nested-routes
    • [x] relative-routes
    • [x] route-templates
    • [x] parameter-parsing
    • [x] parameter-binding
    • [x] parameter-types
  • advanced-features
    • [x] replace-dynamic-segments
    • [x] global-query-parameters
  • customization
    • [x] custom-parameter-types
  • tutorials
    • [x] angular router
    • [ ] react router
    • [ ] wouter
    • [ ] vue router
    • [ ] refine