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

convert-route

v0.1.2

Published

Convert between rou3, Next.js, and path-to-regexp route patterns

Readme

convert-route

Convert between path-to-regexp, rou3, next.js, RegExp, etc. route patterns.

Table of Contents

Installation

npm install convert-route
# or
yarn add convert-route
# or
pnpm add convert-route

Usage

import { fromPathToRegexpV8 } from 'convert-route/path-to-regexp-v8';
import { toRou3 } from 'convert-route/rou3';

// Convert from path-to-regexp v8 format to rou3 format
const rou3Pattern = toRou3(fromPathToRegexpV8('/users/*id'));
console.log(rou3Pattern); // ['/users/**:id']

Supported Features

| Feature | Next.js | rou3 | path-to-regexp v6 | path-to-regexp v8 | RegExp | |----------------------|----------------|----------------|-------------------|-------------------|--------| | Named Segments | [param] | :param | :param | :param | Yes | | Optional Segments | No | *, *:param | :param? | {/:param} | Yes | | Catch-all (Wildcard) | [...param] | **:param | :param+ | *param | Yes | | Optional Catch-all | [[...param]] | ** | :param* | {/*param} | Yes | | Suffix Matching | No | WIP | WIP | WIP | WIP | | Prefix Matching | No | WIP | WIP | WIP | WIP |

rou3

import { fromRou3, toRou3 } from 'convert-route/rou3';

const intermediateRepresentation = fromRou3('/users/:id');
const rou3Pattern = toRou3(intermediateRepresentation);
// Note: toRou3 returns an array of patterns since some patterns need to be expressed as a combination of multiple patterns
console.log(rou3Pattern); // ['/users/:id']

Next.js

// Note: There is no `toNextFs` function. If you have a need for such helper, please open an issue
import { fromNextFs } from 'convert-route/next-fs';

const intermediateRepresentation = fromNextFs('/users/[id]');

path-to-regexp v6

import { fromPathToRegexpV6, toPathToRegexpV6 } from 'convert-route/path-to-regexp-v6';

const intermediateRepresentation = fromPathToRegexpV6('/users/:id');
const pathToRegexV6Pattern = toPathToRegexpV6(intermediateRepresentation);
console.log(pathToRegexV6Pattern); // '/users/:id'

path-to-regexp v8

import { fromPathToRegexpV8, toPathToRegexpV8 } from 'convert-route/path-to-regexp-v8';

const intermediateRepresentation = fromPathToRegexpV8('/users/:id');
const pathToRegexV8Pattern = toPathToRegexpV8(intermediateRepresentation);
console.log(pathToRegexV8Pattern); // '/users/:id'

RegExp

import { toRegexp } from 'convert-route/regexp';
import { fromPathToRegexpV8 } from 'convert-route/path-to-regexp-v8';

const intermediateRepresentation = fromPathToRegexpV8('/users/:id');
const regexp = toRegexp(intermediateRepresentation);
console.log(regexp); // /^\/users\/(?<id>[^/]+)\/?$/