path-parser

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

Install

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

Overview

A small utility to parse, match and generate paths

Index

Classes

class Path

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

    constructor

    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>;

                                          Interfaces

                                          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 https://github.com/troch/search-params#options

                                                        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 ':')

                                                                        https://www.ietf.org/rfc/rfc3986.txt

                                                                        reserved = gen-delims / sub-delims

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

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

                                                                      Package Files (3)

                                                                      Dependencies (2)

                                                                      Dev Dependencies (5)

                                                                      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-parser.

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