pillarjs / path-to-regexp
Turn a path string such as `/user/:name` into a regular expression
AI Architecture Analysis
This repository is indexed by RepoMind. By analyzing pillarjs/path-to-regexp in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.
Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.
Repository Overview (README excerpt)
Crawler viewPath-to-RegExp > Turn a path string such as into a regular expression. [![NPM version][npm-image]][npm-url] [![NPM downloads][downloads-image]][downloads-url] [![Build status][build-image]][build-url] [![Build coverage][coverage-image]][coverage-url] [![License][license-image]][license-url] Installation Usage Parameters Parameters match arbitrary strings in a path by matching up to the end of the segment, or up to any proceeding tokens. They are defined by prefixing a colon to the parameter name ( ). Parameter names can use any valid JavaScript identifier, or be double quoted to use other characters ( ). Wildcard Wildcard parameters match one or more characters across multiple segments. They are defined the same way as regular parameters, but are prefixed with an asterisk ( ). Optional Braces can be used to define parts of the path that are optional. Match The function returns a function for matching strings against a path: • **path** String, object, or array of strings and objects. • **options** _(optional)_ (Extends pathToRegexp options) • **decode** Function for decoding strings to params, or to disable all processing. (default: ) **Please note:** is intended for ordered data (e.g. paths, hosts). It can not handle arbitrarily ordered data (e.g. query strings, URL fragments, JSON, etc). PathToRegexp The function returns the for matching strings against paths, and an array of for understanding the matches. • **path** String, object, or array of strings and objects. • **options** _(optional)_ (See parse for more options) • **sensitive** Regexp will be case sensitive. (default: ) • **end** Validate the match reaches the end of the string. (default: ) • **delimiter** The default delimiter for segments, e.g. for parameters. (default: ) • **trailing** Allows optional trailing delimiter to match. (default: ) Compile ("Reverse" Path-To-RegExp) The function will return a function for transforming parameters into a valid path: • **path** A string or object. • **options** (See parse for more options) • **delimiter** The default delimiter for segments, e.g. for parameters. (default: ) • **encode** Function for encoding input strings for output into the path, or to disable entirely. (default: ) Stringify Transform a object to a Path-to-RegExp string. • **data** A object. Developers • If you are rewriting paths with match and compile, consider using and to keep raw paths passed around. • To ensure matches work on paths containing characters usually encoded, such as emoji, consider using encodeurl for . Parse The function accepts a string and returns , which can be used with and . • **path** A string. • **options** _(optional)_ • **encodePath** A function for encoding input strings. (default: , recommended: ) Tokens has two properties: • **tokens** A sequence of tokens, currently of types , , , or . • **originalPath** The original path used with , shown in error messages to assist debugging. Custom path In some applications you may not be able to use the syntax, but you still want to use this library for and . For example: Errors An effort has been made to ensure ambiguous paths from previous releases throw an error. This means you might be seeing an error when things worked before. Missing parameter name Parameter names must be provided after or , for example . They can be valid JavaScript identifiers (e.g. ) or JSON strings ( ). Unexpected or In past releases, , , and were used to denote optional or repeating parameters. As an alternative, try these: • For optional ( ), use braces: . • For one or more ( ), use a wildcard: . • For zero or more ( ), use both: . Unexpected , , , , etc. Previous versions of Path-to-RegExp used these for RegExp features. This version no longer supports them so they've been reserved to avoid ambiguity. To match these characters literally, escape them with a backslash, e.g. . Unterminated quote Parameter names can be wrapped in double quote characters, and this error means you forgot to close the quote character. For example, . Express <= 4.x Path-To-RegExp breaks compatibility with Express <= in the following ways: • The wildcard must have a name and matches the behavior of parameters . • The optional character is no longer supported, use braces instead: . • Regexp characters are not supported. • Some characters have been reserved to avoid confusion during upgrade ( ). • Parameter names now support valid JavaScript identifiers, or quoted like . License MIT [npm-image]: https://img.shields.io/npm/v/path-to-regexp [npm-url]: https://npmjs.org/package/path-to-regexp [downloads-image]: https://img.shields.io/npm/dm/path-to-regexp [downloads-url]: https://npmjs.org/package/path-to-regexp [build-image]: https://img.shields.io/github/actions/workflow/status/pillarjs/path-to-regexp/ci.yml?branch=master [build-url]: https://github.com/pillarjs/path-to-regexp/actions/workflows/ci.yml?query=branch%3Amaster [coverage-image]: https://img.shields.io/codecov/c/gh/pillarjs/path-to-regexp [coverage-url]: https://codecov.io/gh/pillarjs/path-to-regexp [license-image]: http://img.shields.io/npm/l/path-to-regexp.svg?style=flat [license-url]: LICENSE.md