Gathering detailed insights and metrics for @tehshrike/regexparam
Gathering detailed insights and metrics for @tehshrike/regexparam
Gathering detailed insights and metrics for @tehshrike/regexparam
Gathering detailed insights and metrics for @tehshrike/regexparam
A tiny (332B) utility that converts route patterns into RegExp. Limited alternative to `path-to-regexp` 🙇♂️
npm install @tehshrike/regexparam
Typescript
Module System
Min. Node Version
Node Version
NPM Version
67.7
Supply Chain
95.1
Quality
74.8
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
32 Commits
2 Watchers
1 Branches
1 Contributors
Updated on Feb 05, 2019
Latest Version
1.0.2
Package Id
@tehshrike/regexparam@1.0.2
Unpacked Size
7.01 kB
Size
2.95 kB
File Count
5
NPM Version
6.4.1
Node Version
10.14.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
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:
/foo
, /foo/bar
)/:title
, /books/:title
, /books/:genre/:title
)/:title?
, /books/:title?
, /books/:genre/:title?
)*
, /books/*
, /books/:genre/*
)/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:
dist/regexparam.mjs
dist/regexparam.js
$ npm install --save @tehshrike/regexparam
const regexparam = require('@tehshrike/regexparam');
1 2let foo = regexparam('users/*') 3foo.keys // => ['wild'] 4foo.pattern // => /^\/users\/(.*)(?:\/)?\/?$/i 5 6let bar = regexparam('/books/:genre/:title?') 7bar.keys // => ['genre', 'title'] 8bar.pattern // => /^\/books\/([^\/]+?)(?:\/([^\/]+?))?(?:\/)?\/?$/i 9 10bar.pattern.test('/books/horror') //=> true 11bar.pattern.test('/books/horror/goosebumps') //=> true 12 13// Example param-assignment 14function exec(path, { keys, pattern }) { 15 const matches = pattern.exec(path) 16 const out = {} 17 keys.forEach((key, i) => { 18 out[key] = matches[i + 1] || null 19 }) 20 21 return out 22} 23 24exec('/books/horror', bar) //=> { genre:'horror', title:null } 25 26exec('/books/horror/goosebumps', bar) //=> { genre:'horror', title:'goosebumps' }
Important: When matching/testing against a generated RegExp, your path must begin with a leading slash (
"/"
)!
Returns: Object
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.
MIT © Luke Edwards
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
9 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More