{"id":13468396,"url":"https://github.com/lukeed/regexparam","last_synced_at":"2025-10-09T18:24:06.846Z","repository":{"id":31766544,"uuid":"128681730","full_name":"lukeed/regexparam","owner":"lukeed","description":"A tiny (394B) utility that converts route patterns into RegExp. Limited alternative to `path-to-regexp` 🙇‍♂️","archived":false,"fork":false,"pushed_at":"2023-12-03T21:39:16.000Z","size":59,"stargazers_count":590,"open_issues_count":7,"forks_count":24,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-09-11T17:34:56.730Z","etag":null,"topics":["path-to-regexp","regex","regexp","router"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukeed.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"lukeed"}},"created_at":"2018-04-08T21:02:42.000Z","updated_at":"2025-08-27T13:22:21.000Z","dependencies_parsed_at":"2024-01-10T18:34:52.909Z","dependency_job_id":null,"html_url":"https://github.com/lukeed/regexparam","commit_stats":{"total_commits":76,"total_committers":4,"mean_commits":19.0,"dds":"0.052631578947368474","last_synced_commit":"fff88a167de022ebccb760ce606cf13ff7ceec44"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/lukeed/regexparam","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fregexparam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fregexparam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fregexparam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fregexparam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeed","download_url":"https://codeload.github.com/lukeed/regexparam/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fregexparam/sbom","scorecard":{"id":604517,"data":{"date":"2025-08-11","repo":{"name":"github.com/lukeed/regexparam","commit":"d05da2631beb7c5620774dae207cb09c7cbf24cc"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.6,"checks":[{"name":"Code-Review","score":2,"reason":"Found 4/19 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/lukeed/regexparam/ci.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/lukeed/regexparam/ci.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/lukeed/regexparam/ci.yml/main?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:26","Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:30","Warn: downloadThenRun not pinned by hash: .github/workflows/ci.yml:43","Info:   0 out of   3 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 npmCommand dependencies pinned","Info:   0 out of   1 downloadThenRun dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: license:0","Info: FSF or OSI recognized license: MIT License: license:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 16 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-21T01:16:15.274Z","repository_id":31766544,"created_at":"2025-08-21T01:16:15.274Z","updated_at":"2025-08-21T01:16:15.274Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001940,"owners_count":26083226,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["path-to-regexp","regex","regexp","router"],"created_at":"2024-07-31T15:01:10.057Z","updated_at":"2025-10-09T18:24:06.792Z","avatar_url":"https://github.com/lukeed.png","language":"JavaScript","funding_links":["https://github.com/sponsors/lukeed"],"categories":["JavaScript","Routers and URL Utils"],"sub_categories":["Reactive Programming"],"readme":"# regexparam [![CI](https://github.com/lukeed/regexparam/actions/workflows/ci.yml/badge.svg)](https://github.com/lukeed/regexparam/actions/workflows/ci.yml)\n\n\u003e A tiny (399B) utility that converts route patterns into RegExp. Limited alternative to [`path-to-regexp`](https://github.com/pillarjs/path-to-regexp) 🙇\n\nWith `regexparam`, you may turn a pathing string (eg, `/users/:id`) into a regular expression.\n\nAn 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.\n\nUnlike [`path-to-regexp`](https://github.com/pillarjs/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, `regexparam` **only** handles basic pathing operators:\n\n* Static (`/foo`, `/foo/bar`)\n* Parameter (`/:title`, `/books/:title`, `/books/:genre/:title`)\n* Parameter w/ Suffix (`/movies/:title.mp4`, `/movies/:title.(mp4|mov)`)\n* Optional Parameters (`/:title?`, `/books/:title?`, `/books/:genre/:title?`)\n* Wildcards (`*`, `/books/*`, `/books/:genre/*`)\n* Optional Wildcard (`/books/*?`)\n\nThis module exposes three module definitions:\n\n* **CommonJS**: [`dist/index.js`](https://unpkg.com/regexparam/dist/index.js)\n* **ESModule**: [`dist/index.mjs`](https://unpkg.com/regexparam/dist/index.mjs)\n* **UMD**: [`dist/index.min.js`](https://unpkg.com/regexparam/dist/index.min.js)\n\n## Install\n\n```\n$ npm install --save regexparam\n```\n\n\n## Usage\n\n```js\nimport { parse, inject } from 'regexparam';\n\n// Example param-assignment\nfunction exec(path, result) {\n  let i=0, out={};\n  let matches = result.pattern.exec(path);\n  while (i \u003c result.keys.length) {\n    out[ result.keys[i] ] = matches[++i] || null;\n  }\n  return out;\n}\n\n\n// Parameter, with Optional Parameter\n// ---\nlet foo = parse('/books/:genre/:title?')\n// foo.pattern =\u003e /^\\/books\\/([^\\/]+?)(?:\\/([^\\/]+?))?\\/?$/i\n// foo.keys =\u003e ['genre', 'title']\n\nfoo.pattern.test('/books/horror'); //=\u003e true\nfoo.pattern.test('/books/horror/goosebumps'); //=\u003e true\n\nexec('/books/horror', foo);\n//=\u003e { genre: 'horror', title: null }\n\nexec('/books/horror/goosebumps', foo);\n//=\u003e { genre: 'horror', title: 'goosebumps' }\n\n\n// Parameter, with suffix\n// ---\nlet bar = parse('/movies/:title.(mp4|mov)');\n// bar.pattern =\u003e /^\\/movies\\/([^\\/]+?)\\.(mp4|mov)\\/?$/i\n// bar.keys =\u003e ['title']\n\nbar.pattern.test('/movies/narnia'); //=\u003e false\nbar.pattern.test('/movies/narnia.mp3'); //=\u003e false\nbar.pattern.test('/movies/narnia.mp4'); //=\u003e true\n\nexec('/movies/narnia.mp4', bar);\n//=\u003e { title: 'narnia' }\n\n\n// Wildcard\n// ---\nlet baz = parse('users/*');\n// baz.pattern =\u003e /^\\/users\\/(.*)\\/?$/i\n// baz.keys =\u003e ['*']\n\nbaz.pattern.test('/users'); //=\u003e false\nbaz.pattern.test('/users/lukeed'); //=\u003e true\nbaz.pattern.test('/users/'); //=\u003e true\n\n\n// Optional Wildcard\n// ---\nlet baz = parse('/users/*?');\n// baz.pattern =\u003e /^\\/users(?:\\/(.*))?(?=$|\\/)/i\n// baz.keys =\u003e ['*']\n\nbaz.pattern.test('/users'); //=\u003e true\nbaz.pattern.test('/users/lukeed'); //=\u003e true\nbaz.pattern.test('/users/'); //=\u003e true\n\n\n// Injecting\n// ---\n\ninject('/users/:id', {\n  id: 'lukeed'\n}); //=\u003e '/users/lukeed'\n\ninject('/movies/:title.mp4', {\n  title: 'narnia'\n}); //=\u003e '/movies/narnia.mp4'\n\ninject('/:foo/:bar?/:baz?', {\n  foo: 'aaa'\n}); //=\u003e '/aaa'\n\ninject('/:foo/:bar?/:baz?', {\n  foo: 'aaa',\n  baz: 'ccc'\n}); //=\u003e '/aaa/ccc'\n\ninject('/posts/:slug/*', {\n  slug: 'hello',\n}); //=\u003e '/posts/hello'\n\ninject('/posts/:slug/*', {\n  slug: 'hello',\n  '*': 'x/y/z',\n}); //=\u003e '/posts/hello/x/y/z'\n\n// Missing non-optional value\n// ~\u003e keeps the pattern in output\ninject('/hello/:world', {\n  abc: 123\n}); //=\u003e '/hello/:world'\n```\n\n\u003e **Important:** When matching/testing against a generated RegExp, your path **must** begin with a leading slash (`\"/\"`)!\n\n## Regular Expressions\n\nFor fine-tuned control, you may pass a `RegExp` value directly to `regexparam` as its only parameter.\n\nIn these situations, `regexparam` **does not** parse nor manipulate your pattern in any way! Because of this, `regexparam` has no \"insight\" on your route, and instead trusts your input fully. In code, this means that the return value's `keys` is always equal to `false` and the `pattern` is identical to your input value.\n\nThis also means that you must manage and parse your own `keys`~!\u003cbr\u003e\nYou may use [named capture groups](https://javascript.info/regexp-groups#named-groups) or traverse the matched segments manually the \"old-fashioned\" way:\n\n\u003e **Important:** Please check your target browsers' and target [Node.js runtimes' support](https://node.green/#ES2018-features--RegExp-named-capture-groups)!\n\n```js\n// Named capture group\nconst named = regexparam.parse(/^\\/posts[/](?\u003cyear\u003e[0-9]{4})[/](?\u003cmonth\u003e[0-9]{2})[/](?\u003ctitle\u003e[^\\/]+)/i);\nconst { groups } = named.pattern.exec('/posts/2019/05/hello-world');\nconsole.log(groups);\n//=\u003e { year: '2019', month: '05', title: 'hello-world' }\n\n// Widely supported / \"Old-fashioned\"\nconst named = regexparam.parse(/^\\/posts[/]([0-9]{4})[/]([0-9]{2})[/]([^\\/]+)/i);\nconst [url, year, month, title] = named.pattern.exec('/posts/2019/05/hello-world');\nconsole.log(year, month, title);\n//=\u003e 2019 05 hello-world\n```\n\n\n## API\n\n### regexparam.parse(input: RegExp)\n### regexparam.parse(input: string, loose?: boolean)\nReturns: `Object`\n\nParse a route pattern into an equivalent RegExp pattern. Also collects the names of pattern's parameters as a `keys` array. An `input` that's already a RegExp is kept as is, and `regexparam` makes no additional insights.\n\nReturns a `{ keys, pattern }` object, where `pattern` is always a `RegExp` instance and `keys` is either `false` or a list of extracted parameter names.\n\n\u003e **Important:** The `keys` will _always_ be `false` when `input` is a RegExp and it will _always_ be an Array when `input` is a string.\n\n#### input\nType: `string` or `RegExp`\n\nWhen `input` is a string, it's treated as a route pattern and an equivalent RegExp is generated.\n\n\u003e **Note:** It does not matter if `input` strings begin with a `/` \u0026mdash; it will be added if missing.\n\nWhen `input` is a RegExp, it will be used **as is** – no modifications will be made.\n\n#### loose\nType: `boolean`\u003cbr\u003e\nDefault: `false`\n\nShould the `RegExp` match URLs that are longer than the [`str`](#str) pattern itself?\u003cbr\u003e\nBy default, the generated `RegExp` will test that the URL begins and _ends with_ the pattern.\n\n\u003e **Important:** When `input` is a RegExp, the `loose` argument is ignored!\n\n```js\nconst { parse } = require('regexparam');\n\nparse('/users').pattern.test('/users/lukeed'); //=\u003e false\nparse('/users', true).pattern.test('/users/lukeed'); //=\u003e true\n\nparse('/users/:name').pattern.test('/users/lukeed/repos'); //=\u003e false\nparse('/users/:name', true).pattern.test('/users/lukeed/repos'); //=\u003e true\n```\n\n\n### regexparam.inject(pattern: string, values: object)\nReturns: `string`\n\nReturns a new string by replacing the `pattern` segments/parameters with their matching values.\n\n\u003e **Important:** Named segments (eg, `/:name`) that _do not_ have a `values` match will be kept in the output. This is true _except for_ optional segments (eg, `/:name?`) and wildcard segments (eg, `/*`).\n\n#### pattern\nType: `string`\n\nThe route pattern that to receive injections.\n\n#### values\nType: `Record\u003cstring, string\u003e`\n\nThe values to be injected. The keys within `values` must match the `pattern`'s segments in order to be replaced.\n\n\u003e **Note:** To replace a wildcard segment (eg, `/*`), define a `values['*']` key.\n\n\n## Deno\n\nAs of version `1.3.0`, you may use `regexparam` with Deno. These options are all valid:\n\n```ts\n// The official Deno registry:\nimport regexparam from 'https://deno.land/x/regexparam/src/index.js';\n// Third-party CDNs with ESM support:\nimport regexparam from 'https://cdn.skypack.dev/regexparam';\nimport regexparam from 'https://esm.sh/regexparam';\n```\n\n\u003e **Note:** All registries support versioned URLs, if desired. \u003cbr\u003eThe above examples always resolve to the latest published version.\n\n\n## Related\n\n- [trouter](https://github.com/lukeed/trouter) - A server-side HTTP router that extends from this module.\n- [matchit](https://github.com/lukeed/matchit) - Similar (650B) library, but relies on String comparison instead of `RegExp`s.\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fregexparam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeed%2Fregexparam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fregexparam/lists"}