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

@tehshrike/regexparam

v1.0.2

Published

A tiny (332B) utility that converts route patterns into RegExp. Limited alternative to `path-to-regexp` 🙇‍

Readme

@tehshrike/regexparam

regexparam with longer variable names and support for custom regex patterns.

A tiny (332B) utility that converts route patterns into RegExp. Limited alternative to path-to-regexp 🙇

With @tehshrike/regexparam, you may turn a pathing string (eg, /users/:id) into a regular expression.

An object with shape of { keys, pattern } is returned, where pattern is the RegExp and keys is an array of your parameter name(s) in the order that they appeared.

Unlike path-to-regexp, this module does not create a keys dictionary, nor mutate an existing variable. Also, this only ships a parser, which only accept strings. Similarly, and most importantly, @tehshrike/regexparam only handles basic pathing operators:

  • Static (/foo, /foo/bar)
  • Parameter (/:title, /books/:title, /books/:genre/:title)
  • Optional Parameters (/:title?, /books/:title?, /books/:genre/:title?)
  • Wildcards (*, /books/*, /books/:genre/*)
  • Regex Parameters (/user/:userId(\\d+))

Lastly, please note that while this route-parser is not slow, you should use matchit or trouter if performance is of critical importance. This is especially true for backend/server scenarios!

This module exposes two module definitions:

  • ES Module: dist/regexparam.mjs
  • CommonJS: dist/regexparam.js

Install

$ npm install --save @tehshrike/regexparam

Usage

const regexparam = require('@tehshrike/regexparam');

let foo = regexparam('users/*')
foo.keys // => ['wild']
foo.pattern // => /^\/users\/(.*)(?:\/)?\/?$/i

let bar = regexparam('/books/:genre/:title?')
bar.keys // => ['genre', 'title']
bar.pattern // => /^\/books\/([^\/]+?)(?:\/([^\/]+?))?(?:\/)?\/?$/i

bar.pattern.test('/books/horror') //=> true
bar.pattern.test('/books/horror/goosebumps') //=> true

// Example param-assignment
function exec(path, { keys, pattern }) {
	const matches = pattern.exec(path)
	const out = {}
	keys.forEach((key, i) => {
		out[key] = matches[i + 1] || null
	})

	return out
}

exec('/books/horror', bar) //=> { genre:'horror', title:null }

exec('/books/horror/goosebumps', bar) //=> { genre:'horror', title:'goosebumps' }

Important: When matching/testing against a generated RegExp, your path must begin with a leading slash ("/")!

API

regexparam(str)

Returns: Object

str

Type: String

The route/pathing string to convert.

Note: It does not matter if your str begins with a / — it will be added if missing.

License

MIT © Luke Edwards