path-to-regexp

  • Version 8.2.0
  • Published
  • 55.2 kB
  • No dependencies
  • MIT license

Install

npm i path-to-regexp
yarn add path-to-regexp
pnpm add path-to-regexp

Overview

Express style path to RegExp utility

Index

Functions

function compile

compile: <
P extends Partial<Record<string, string | string[]>> = Partial<
Record<string, string | string[]>
>
>(
path: Path,
options?: CompileOptions & ParseOptions
) => (data?: P) => string;
  • Compile a string to a template function for the path.

function match

match: <P extends Partial<Record<string, string | string[]>>>(
path: Path | Path[],
options?: MatchOptions & ParseOptions
) => MatchFunction<P>;
  • Transform a path into a match function.

function parse

parse: (str: string, options?: ParseOptions) => TokenData;
  • Parse a string for the raw tokens.

function pathToRegexp

pathToRegexp: (
path: Path | Path[],
options?: PathToRegexpOptions & ParseOptions
) => { regexp: RegExp; keys: Keys };

    function stringify

    stringify: (data: TokenData) => string;
    • Stringify token data into a path string.

    Classes

    class TokenData

    class TokenData {}
    • Tokenized path instance.

    constructor

    constructor(tokens: Token[]);

      property tokens

      readonly tokens: Token[];

        Interfaces

        interface CompileOptions

        interface CompileOptions {}

          property delimiter

          delimiter?: string;
          • The default delimiter for segments. (default: '/')

          property encode

          encode?: Encode | false;
          • Function for encoding input strings for output into the path, or false to disable entirely. (default: encodeURIComponent)

          interface Group

          interface Group {}
          • A set of possible tokens to expand when matching.

          property tokens

          tokens: Token[];

            property type

            type: 'group';

              interface MatchOptions

              interface MatchOptions extends PathToRegexpOptions {}

                property decode

                decode?: Decode | false;
                • Function for decoding strings for params, or false to disable entirely. (default: decodeURIComponent)

                interface MatchResult

                interface MatchResult<P extends ParamData> {}
                • A match result contains data about the path match.

                property params

                params: P;

                  property path

                  path: string;

                    interface Parameter

                    interface Parameter {}
                    • A parameter designed to match arbitrary text within a segment.

                    property name

                    name: string;

                      property type

                      type: 'param';

                        interface ParseOptions

                        interface ParseOptions {}

                          property encodePath

                          encodePath?: Encode;
                          • A function for encoding input strings.

                          interface PathToRegexpOptions

                          interface PathToRegexpOptions {}

                            property delimiter

                            delimiter?: string;
                            • The default delimiter for segments. (default: '/')

                            property end

                            end?: boolean;
                            • Matches the path completely without trailing characters. (default: true)

                            property sensitive

                            sensitive?: boolean;
                            • Match will be case sensitive. (default: false)

                            property trailing

                            trailing?: boolean;
                            • Allows optional trailing delimiter to match. (default: true)

                            interface Text

                            interface Text {}
                            • Plain text.

                            property type

                            type: 'text';

                              property value

                              value: string;

                                interface Wildcard

                                interface Wildcard {}
                                • A wildcard parameter designed to match multiple segments.

                                property name

                                name: string;

                                  property type

                                  type: 'wildcard';

                                    Type Aliases

                                    type Decode

                                    type Decode = (value: string) => string;
                                    • Decode a string into another string.

                                    type Encode

                                    type Encode = (value: string) => string;
                                    • Encode a string into another string.

                                    type Key

                                    type Key = Parameter | Wildcard;
                                    • A token that corresponds with a regexp capture.

                                    type Keys

                                    type Keys = Array<Key>;
                                    • A sequence of path-to-regexp keys that match capturing groups.

                                    type Match

                                    type Match<P extends ParamData> = false | MatchResult<P>;
                                    • A match is either false (no match) or a match result.

                                    type MatchFunction

                                    type MatchFunction<P extends ParamData> = (path: string) => Match<P>;
                                    • The match function takes a string and returns whether it matched the path.

                                    type ParamData

                                    type ParamData = Partial<Record<string, string | string[]>>;

                                      type Path

                                      type Path = string | TokenData;
                                      • Supported path types.

                                      type PathFunction

                                      type PathFunction<P extends ParamData> = (data?: P) => string;

                                        type Token

                                        type Token = Text | Parameter | Wildcard | Group;
                                        • A sequence of path match characters.

                                        Package Files (1)

                                        Dependencies (0)

                                        No dependencies.

                                        Dev Dependencies (8)

                                        Peer Dependencies (0)

                                        No peer dependencies.

                                        Badge

                                        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/path-to-regexp.

                                        • Markdown
                                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/path-to-regexp)
                                        • HTML
                                          <a href="https://www.jsdocs.io/package/path-to-regexp"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>