• Version 6.1.0
  • Published
  • 128 kB
  • 2 dependencies
  • MIT license


npm i path-parser
yarn add path-parser
pnpm add path-parser


A small utility to parse, match and generate paths



class Path

class Path<T extends Record<string, any> = Record<string, any>> {}


    constructor(path: string, options?: PathOptions);

      property hasMatrixParams

      hasMatrixParams: boolean;

        property hasQueryParams

        hasQueryParams: boolean;

          property hasSpatParam

          hasSpatParam: boolean;

            property hasUrlParams

            hasUrlParams: boolean;

              property options

              options: InternalPathOptions;

                property params

                params: string[];

                  property path

                  path: string;

                    property queryParams

                    queryParams: string[];

                      property source

                      source: string;

                        property spatParams

                        spatParams: string[];

                          property tokens

                          tokens: Token[];

                            property urlParams

                            urlParams: string[];

                              method build

                              build: (params?: T, opts?: PathBuildOptions) => string;

                                method createPath

                                static createPath: <T extends Record<string, any> = Record<string, any>>(
                                path: string,
                                options?: PathOptions
                                ) => Path<T>;

                                  method isQueryParam

                                  isQueryParam: (name: string) => boolean;

                                    method isSpatParam

                                    isSpatParam: (name: string) => boolean;

                                      method partialTest

                                      partialTest: (path: string, opts?: PathPartialTestOptions) => TestMatch<T>;

                                        method test

                                        test: (path: string, opts?: PathTestOptions) => TestMatch<T>;


                                          interface InternalPathOptions

                                          interface InternalPathOptions {}

                                            property queryParams

                                            queryParams?: IOptions;

                                              property urlParamsEncoding

                                              urlParamsEncoding: URLParamsEncodingType;

                                                interface PathBuildOptions

                                                interface PathBuildOptions extends PathOptions {}

                                                  property ignoreConstraints

                                                  ignoreConstraints?: boolean;

                                                    property ignoreSearch

                                                    ignoreSearch?: boolean;

                                                      interface PathOptions

                                                      interface PathOptions {}

                                                        property queryParams

                                                        queryParams?: IOptions;
                                                        • Query parameters buiding and matching options, see

                                                        property urlParamsEncoding

                                                        urlParamsEncoding?: URLParamsEncodingType;
                                                        • Specifies the method used to encode URL parameters: - 'default': encodeURIComponent and decodeURIComponent` are used but some characters to encode and decode URL parameters, but some characters are preserved when encoding (sub-delimiters: +, :, ', !, ,, ;, '*'). - 'uriComponent': use encodeURIComponent and decodeURIComponent for encoding and decoding URL parameters. - 'uri': use encodeURI and `decodeURI for encoding amd decoding URL parameters. - 'none': no encoding or decoding is performed - 'legacy': the approach for version 5.x and below (not recoomended)

                                                        interface PathPartialTestOptions

                                                        interface PathPartialTestOptions extends PathOptions {}

                                                          property caseSensitive

                                                          caseSensitive?: boolean;

                                                            property delimited

                                                            delimited?: boolean;

                                                              interface PathTestOptions

                                                              interface PathTestOptions extends PathOptions {}

                                                                property caseSensitive

                                                                caseSensitive?: boolean;

                                                                  property strictTrailingSlash

                                                                  strictTrailingSlash?: boolean;

                                                                    Type Aliases

                                                                    type TestMatch

                                                                    type TestMatch<T extends Record<string, any> = Record<string, any>> = T | null;

                                                                      type URLParamsEncodingType

                                                                      type URLParamsEncodingType = 'default' | 'uri' | 'uriComponent' | 'none' | 'legacy';
                                                                      • We encode using encodeURIComponent but we want to preserver certain characters which are commonly used (sub delimiters and ':')


                                                                        reserved = gen-delims / sub-delims

                                                                        gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"

                                                                        sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="

                                                                      Package Files (3)

                                                                      Dependencies (2)

                                                                      Dev Dependencies (5)

                                                                      Peer Dependencies (0)

                                                                      No peer dependencies.


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

                                                                      You may also use to create a custom badge linking to

                                                                      • Markdown
                                                                      • HTML
                                                                        <a href=""><img src="" alt=""></a>