@contrast/agent-bundle 5.39.1 → 5.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/node_modules/@contrast/agent/lib/start-agent.js +50 -40
  2. package/node_modules/@contrast/agent/package.json +10 -10
  3. package/node_modules/@contrast/agentify/lib/sources.js +1 -0
  4. package/node_modules/@contrast/agentify/package.json +14 -14
  5. package/node_modules/@contrast/architecture-components/package.json +5 -5
  6. package/node_modules/@contrast/assess/lib/dataflow/propagation/install/string/replace.js +6 -3
  7. package/node_modules/@contrast/assess/lib/dataflow/sources/index.js +1 -1
  8. package/node_modules/@contrast/assess/lib/dataflow/sources/install/{body-parser1.js → body-parser.js} +1 -1
  9. package/node_modules/@contrast/assess/package.json +11 -11
  10. package/node_modules/@contrast/common/lib/constants.d.ts +6 -0
  11. package/node_modules/@contrast/common/lib/constants.js +8 -1
  12. package/node_modules/@contrast/common/package.json +1 -1
  13. package/node_modules/@contrast/config/lib/index.d.ts +1 -0
  14. package/node_modules/@contrast/config/package.json +3 -3
  15. package/node_modules/@contrast/core/package.json +5 -5
  16. package/node_modules/@contrast/deadzones/package.json +5 -5
  17. package/node_modules/@contrast/dep-hooks/package.json +3 -3
  18. package/node_modules/@contrast/esm-hooks/package.json +6 -6
  19. package/node_modules/@contrast/instrumentation/package.json +5 -5
  20. package/node_modules/@contrast/library-analysis/lib/install/library-reporting/dep.json +143 -145
  21. package/node_modules/@contrast/library-analysis/lib/install/library-reporting/index.js +9 -2
  22. package/node_modules/@contrast/library-analysis/lib/install/library-reporting/utils.js +54 -43
  23. package/node_modules/@contrast/library-analysis/package.json +4 -4
  24. package/node_modules/@contrast/logger/package.json +3 -3
  25. package/node_modules/@contrast/metrics/package.json +6 -6
  26. package/node_modules/@contrast/patcher/package.json +2 -2
  27. package/node_modules/@contrast/protect/lib/input-analysis/index.js +1 -1
  28. package/node_modules/@contrast/protect/lib/input-analysis/install/{body-parser1.js → body-parser.js} +1 -1
  29. package/node_modules/@contrast/protect/package.json +11 -11
  30. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/routes-observed.js +2 -1
  31. package/node_modules/@contrast/reporter/package.json +6 -6
  32. package/node_modules/@contrast/rewriter/package.json +5 -5
  33. package/node_modules/@contrast/route-coverage/lib/index.d.ts +2 -0
  34. package/node_modules/@contrast/route-coverage/lib/index.js +14 -8
  35. package/node_modules/@contrast/route-coverage/lib/install/express/express5.js +491 -202
  36. package/node_modules/@contrast/route-coverage/package.json +9 -9
  37. package/node_modules/@contrast/scopes/package.json +5 -5
  38. package/node_modules/@contrast/telemetry/package.json +5 -5
  39. package/node_modules/@types/node/README.md +1 -1
  40. package/node_modules/@types/node/buffer.d.ts +5 -0
  41. package/node_modules/@types/node/dns/promises.d.ts +11 -10
  42. package/node_modules/@types/node/dns.d.ts +18 -19
  43. package/node_modules/@types/node/package.json +2 -2
  44. package/node_modules/@types/node/stream/web.d.ts +4 -0
  45. package/package.json +5 -3
  46. package/node_modules/@contrast/route-coverage/lib/install/http.js +0 -44
  47. package/node_modules/path-to-regexp/LICENSE +0 -21
  48. package/node_modules/path-to-regexp/Readme.md +0 -216
  49. package/node_modules/path-to-regexp/dist/index.d.ts +0 -136
  50. package/node_modules/path-to-regexp/dist/index.js +0 -403
  51. package/node_modules/path-to-regexp/dist/index.js.map +0 -1
  52. package/node_modules/path-to-regexp/package.json +0 -62
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/route-coverage",
3
- "version": "1.45.1",
3
+ "version": "1.45.2",
4
4
  "description": "Handles route discovery and observation",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -20,14 +20,14 @@
20
20
  "test": "bash ../scripts/test.sh"
21
21
  },
22
22
  "dependencies": {
23
- "@contrast/common": "1.34.1",
24
- "@contrast/config": "1.49.1",
25
- "@contrast/dep-hooks": "1.23.1",
23
+ "@contrast/common": "1.34.2",
24
+ "@contrast/config": "1.49.2",
25
+ "@contrast/core": "1.54.2",
26
+ "@contrast/dep-hooks": "1.23.2",
26
27
  "@contrast/fn-inspect": "^4.3.0",
27
- "@contrast/logger": "1.27.1",
28
- "@contrast/patcher": "1.26.1",
29
- "@contrast/scopes": "1.24.1",
30
- "semver": "^7.6.0",
31
- "path-to-regexp": "^8.2.0"
28
+ "@contrast/logger": "1.27.2",
29
+ "@contrast/patcher": "1.26.2",
30
+ "@contrast/scopes": "1.24.2",
31
+ "semver": "^7.6.0"
32
32
  }
33
33
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/scopes",
3
- "version": "1.24.1",
3
+ "version": "1.24.2",
4
4
  "description": "Handles AsyncLocalStorage scopes",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -20,9 +20,9 @@
20
20
  "test": "bash ../scripts/test.sh"
21
21
  },
22
22
  "dependencies": {
23
- "@contrast/core": "1.54.1",
24
- "@contrast/dep-hooks": "1.23.1",
25
- "@contrast/logger": "1.27.1",
26
- "@contrast/patcher": "1.26.1"
23
+ "@contrast/core": "1.54.2",
24
+ "@contrast/dep-hooks": "1.23.2",
25
+ "@contrast/logger": "1.27.2",
26
+ "@contrast/patcher": "1.26.2"
27
27
  }
28
28
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/telemetry",
3
- "version": "1.29.1",
3
+ "version": "1.29.2",
4
4
  "description": "Telemetry reporting for the Contrast Node.js agent.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -19,10 +19,10 @@
19
19
  "test": "bash ../scripts/test.sh"
20
20
  },
21
21
  "dependencies": {
22
- "@contrast/common": "1.34.1",
23
- "@contrast/config": "1.49.1",
24
- "@contrast/core": "1.54.1",
25
- "@contrast/logger": "1.27.1",
22
+ "@contrast/common": "1.34.2",
23
+ "@contrast/config": "1.49.2",
24
+ "@contrast/core": "1.54.2",
25
+ "@contrast/logger": "1.27.2",
26
26
  "axios": "^1.7.4",
27
27
  "getmac": "^6.3.0"
28
28
  }
@@ -8,7 +8,7 @@ This package contains type definitions for node (https://nodejs.org/).
8
8
  Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Tue, 01 Jul 2025 19:02:07 GMT
11
+ * Last updated: Wed, 09 Jul 2025 00:04:35 GMT
12
12
  * Dependencies: [undici-types](https://npmjs.com/package/undici-types)
13
13
 
14
14
  # Credits
@@ -1701,6 +1701,8 @@ declare module "buffer" {
1701
1701
  * @return A reference to `buf`.
1702
1702
  */
1703
1703
  fill(value: string | Uint8Array | number, offset?: number, end?: number, encoding?: BufferEncoding): this;
1704
+ fill(value: string | Uint8Array | number, offset: number, encoding: BufferEncoding): this;
1705
+ fill(value: string | Uint8Array | number, encoding: BufferEncoding): this;
1704
1706
  /**
1705
1707
  * If `value` is:
1706
1708
  *
@@ -1770,6 +1772,7 @@ declare module "buffer" {
1770
1772
  * @return The index of the first occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`.
1771
1773
  */
1772
1774
  indexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number;
1775
+ indexOf(value: string | number | Uint8Array, encoding: BufferEncoding): number;
1773
1776
  /**
1774
1777
  * Identical to `buf.indexOf()`, except the last occurrence of `value` is found
1775
1778
  * rather than the first occurrence.
@@ -1838,6 +1841,7 @@ declare module "buffer" {
1838
1841
  * @return The index of the last occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`.
1839
1842
  */
1840
1843
  lastIndexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number;
1844
+ lastIndexOf(value: string | number | Uint8Array, encoding: BufferEncoding): number;
1841
1845
  /**
1842
1846
  * Equivalent to `buf.indexOf() !== -1`.
1843
1847
  *
@@ -1868,6 +1872,7 @@ declare module "buffer" {
1868
1872
  * @return `true` if `value` was found in `buf`, `false` otherwise.
1869
1873
  */
1870
1874
  includes(value: string | number | Buffer, byteOffset?: number, encoding?: BufferEncoding): boolean;
1875
+ includes(value: string | number | Buffer, encoding: BufferEncoding): boolean;
1871
1876
  }
1872
1877
  var Buffer: BufferConstructor;
1873
1878
  /**
@@ -127,24 +127,25 @@ declare module "dns/promises" {
127
127
  * @param [rrtype='A'] Resource record type.
128
128
  */
129
129
  function resolve(hostname: string): Promise<string[]>;
130
- function resolve(hostname: string, rrtype: "A"): Promise<string[]>;
131
- function resolve(hostname: string, rrtype: "AAAA"): Promise<string[]>;
130
+ function resolve(hostname: string, rrtype: "A" | "AAAA" | "CNAME" | "NS" | "PTR"): Promise<string[]>;
132
131
  function resolve(hostname: string, rrtype: "ANY"): Promise<AnyRecord[]>;
133
132
  function resolve(hostname: string, rrtype: "CAA"): Promise<CaaRecord[]>;
134
- function resolve(hostname: string, rrtype: "CNAME"): Promise<string[]>;
135
133
  function resolve(hostname: string, rrtype: "MX"): Promise<MxRecord[]>;
136
134
  function resolve(hostname: string, rrtype: "NAPTR"): Promise<NaptrRecord[]>;
137
- function resolve(hostname: string, rrtype: "NS"): Promise<string[]>;
138
- function resolve(hostname: string, rrtype: "PTR"): Promise<string[]>;
139
135
  function resolve(hostname: string, rrtype: "SOA"): Promise<SoaRecord>;
140
136
  function resolve(hostname: string, rrtype: "SRV"): Promise<SrvRecord[]>;
141
137
  function resolve(hostname: string, rrtype: "TLSA"): Promise<TlsaRecord[]>;
142
138
  function resolve(hostname: string, rrtype: "TXT"): Promise<string[][]>;
143
- function resolve(
144
- hostname: string,
145
- rrtype: string,
146
- ): Promise<
147
- string[] | MxRecord[] | NaptrRecord[] | SoaRecord | SrvRecord[] | TlsaRecord[] | string[][] | AnyRecord[]
139
+ function resolve(hostname: string, rrtype: string): Promise<
140
+ | string[]
141
+ | CaaRecord[]
142
+ | MxRecord[]
143
+ | NaptrRecord[]
144
+ | SoaRecord
145
+ | SrvRecord[]
146
+ | TlsaRecord[]
147
+ | string[][]
148
+ | AnyRecord[]
148
149
  >;
149
150
  /**
150
151
  * Uses the DNS protocol to resolve IPv4 addresses (`A` records) for the `hostname`. On success, the `Promise` is resolved with an array of IPv4
@@ -250,6 +250,9 @@ declare module "dns" {
250
250
  contactemail?: string | undefined;
251
251
  contactphone?: string | undefined;
252
252
  }
253
+ export interface AnyCaaRecord extends CaaRecord {
254
+ type: "CAA";
255
+ }
253
256
  export interface MxRecord {
254
257
  priority: number;
255
258
  exchange: string;
@@ -317,6 +320,7 @@ declare module "dns" {
317
320
  export type AnyRecord =
318
321
  | AnyARecord
319
322
  | AnyAaaaRecord
323
+ | AnyCaaRecord
320
324
  | AnyCnameRecord
321
325
  | AnyMxRecord
322
326
  | AnyNaptrRecord
@@ -345,12 +349,7 @@ declare module "dns" {
345
349
  ): void;
346
350
  export function resolve(
347
351
  hostname: string,
348
- rrtype: "A",
349
- callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
350
- ): void;
351
- export function resolve(
352
- hostname: string,
353
- rrtype: "AAAA",
352
+ rrtype: "A" | "AAAA" | "CNAME" | "NS" | "PTR",
354
353
  callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
355
354
  ): void;
356
355
  export function resolve(
@@ -360,8 +359,8 @@ declare module "dns" {
360
359
  ): void;
361
360
  export function resolve(
362
361
  hostname: string,
363
- rrtype: "CNAME",
364
- callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
362
+ rrtype: "CAA",
363
+ callback: (err: NodeJS.ErrnoException | null, address: CaaRecord[]) => void,
365
364
  ): void;
366
365
  export function resolve(
367
366
  hostname: string,
@@ -373,16 +372,6 @@ declare module "dns" {
373
372
  rrtype: "NAPTR",
374
373
  callback: (err: NodeJS.ErrnoException | null, addresses: NaptrRecord[]) => void,
375
374
  ): void;
376
- export function resolve(
377
- hostname: string,
378
- rrtype: "NS",
379
- callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
380
- ): void;
381
- export function resolve(
382
- hostname: string,
383
- rrtype: "PTR",
384
- callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
385
- ): void;
386
375
  export function resolve(
387
376
  hostname: string,
388
377
  rrtype: "SOA",
@@ -410,6 +399,7 @@ declare module "dns" {
410
399
  err: NodeJS.ErrnoException | null,
411
400
  addresses:
412
401
  | string[]
402
+ | CaaRecord[]
413
403
  | MxRecord[]
414
404
  | NaptrRecord[]
415
405
  | SoaRecord
@@ -422,6 +412,7 @@ declare module "dns" {
422
412
  export namespace resolve {
423
413
  function __promisify__(hostname: string, rrtype?: "A" | "AAAA" | "CNAME" | "NS" | "PTR"): Promise<string[]>;
424
414
  function __promisify__(hostname: string, rrtype: "ANY"): Promise<AnyRecord[]>;
415
+ function __promisify__(hostname: string, rrtype: "CAA"): Promise<CaaRecord[]>;
425
416
  function __promisify__(hostname: string, rrtype: "MX"): Promise<MxRecord[]>;
426
417
  function __promisify__(hostname: string, rrtype: "NAPTR"): Promise<NaptrRecord[]>;
427
418
  function __promisify__(hostname: string, rrtype: "SOA"): Promise<SoaRecord>;
@@ -432,7 +423,15 @@ declare module "dns" {
432
423
  hostname: string,
433
424
  rrtype: string,
434
425
  ): Promise<
435
- string[] | MxRecord[] | NaptrRecord[] | SoaRecord | SrvRecord[] | TlsaRecord[] | string[][] | AnyRecord[]
426
+ | string[]
427
+ | CaaRecord[]
428
+ | MxRecord[]
429
+ | NaptrRecord[]
430
+ | SoaRecord
431
+ | SrvRecord[]
432
+ | TlsaRecord[]
433
+ | string[][]
434
+ | AnyRecord[]
436
435
  >;
437
436
  }
438
437
  /**
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/node",
3
- "version": "24.0.9",
3
+ "version": "24.0.12",
4
4
  "description": "TypeScript definitions for node",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
6
6
  "license": "MIT",
@@ -235,6 +235,6 @@
235
235
  "undici-types": "~7.8.0"
236
236
  },
237
237
  "peerDependencies": {},
238
- "typesPublisherContentHash": "eca643fa866d5ed2967c0b8798eac27b18ecb6010efe9a7c3e5f99f4513b0684",
238
+ "typesPublisherContentHash": "8e4c85a4e3eaa197d6a1deb2bcccfbcd34ad8ba2f260d598e3576078dbf913d1",
239
239
  "typeScriptVersion": "5.1"
240
240
  }
@@ -143,6 +143,9 @@ declare module "stream/web" {
143
143
  interface TransformerTransformCallback<I, O> {
144
144
  (chunk: I, controller: TransformStreamDefaultController<O>): void | PromiseLike<void>;
145
145
  }
146
+ interface TransformerCancelCallback {
147
+ (reason: any): void | PromiseLike<void>;
148
+ }
146
149
  interface UnderlyingByteSource {
147
150
  autoAllocateChunkSize?: number;
148
151
  cancel?: ReadableStreamErrorCallback;
@@ -261,6 +264,7 @@ declare module "stream/web" {
261
264
  readableType?: undefined;
262
265
  start?: TransformerStartCallback<O>;
263
266
  transform?: TransformerTransformCallback<I, O>;
267
+ cancel?: TransformerCancelCallback;
264
268
  writableType?: undefined;
265
269
  }
266
270
  interface TransformStream<I = any, O = any> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/agent-bundle",
3
- "version": "5.39.1",
3
+ "version": "5.40.0",
4
4
  "description": "Contrast Security Node.js Agent bundle with all dependencies included",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -26,7 +26,9 @@
26
26
  "test": "bash ../scripts/test.sh"
27
27
  },
28
28
  "dependencies": {
29
- "@contrast/agent": "5.39.1"
29
+ "@contrast/agent": "5.40.0"
30
30
  },
31
- "bundleDependencies": true
31
+ "bundleDependencies": [
32
+ "@contrast/agent"
33
+ ]
32
34
  }
@@ -1,44 +0,0 @@
1
- /*
2
- * Copyright: 2025 Contrast Security, Inc
3
- * Contact: support@contrastsecurity.com
4
- * License: Commercial
5
-
6
- * NOTICE: This Software and the patented inventions embodied within may only be
7
- * used as part of Contrast Security’s commercial offerings. Even though it is
8
- * made available through public repositories, use of this Software is subject to
9
- * the applicable End User Licensing Agreement found at
10
- * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
- * between Contrast Security and the End User. The Software may not be reverse
12
- * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
- * way not consistent with the End User License Agreement.
14
- */
15
- 'use strict';
16
-
17
- module.exports = function init(core) {
18
- const { depHooks, patcher, routeCoverage } = core;
19
-
20
- let handled;
21
-
22
- return core.routeCoverage.http = {
23
- install() {
24
- [['http', '*'], ['https', '*'], ['spdy', '<5']].forEach(([name, version]) => {
25
- depHooks.resolve({ name, version }, (_export) => {
26
- if (!_export?.Server?.prototype) return;
27
-
28
- patcher.patch(_export.Server.prototype, 'listen', {
29
- name: `${name}.Server.prototype.listen`,
30
- patchType: 'route-coverage',
31
- post(data) {
32
- data.result?.on('listening', () => {
33
- if (!handled) {
34
- handled = true;
35
- routeCoverage.discoveryFinished();
36
- }
37
- });
38
- }
39
- });
40
- });
41
- });
42
- }
43
- };
44
- };
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1,216 +0,0 @@
1
- # Path-to-RegExp
2
-
3
- > Turn a path string such as `/user/:name` into a regular expression.
4
-
5
- [![NPM version][npm-image]][npm-url]
6
- [![NPM downloads][downloads-image]][downloads-url]
7
- [![Build status][build-image]][build-url]
8
- [![Build coverage][coverage-image]][coverage-url]
9
- [![License][license-image]][license-url]
10
-
11
- ## Installation
12
-
13
- ```
14
- npm install path-to-regexp --save
15
- ```
16
-
17
- ## Usage
18
-
19
- ```js
20
- const {
21
- match,
22
- pathToRegexp,
23
- compile,
24
- parse,
25
- stringify,
26
- } = require("path-to-regexp");
27
- ```
28
-
29
- ### Parameters
30
-
31
- 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 (`:foo`). Parameter names can use any valid JavaScript identifier, or be double quoted to use other characters (`:"param-name"`).
32
-
33
- ```js
34
- const fn = match("/:foo/:bar");
35
-
36
- fn("/test/route");
37
- //=> { path: '/test/route', params: { foo: 'test', bar: 'route' } }
38
- ```
39
-
40
- ### Wildcard
41
-
42
- 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 (`*foo`).
43
-
44
- ```js
45
- const fn = match("/*splat");
46
-
47
- fn("/bar/baz");
48
- //=> { path: '/bar/baz', params: { splat: [ 'bar', 'baz' ] } }
49
- ```
50
-
51
- ### Optional
52
-
53
- Braces can be used to define parts of the path that are optional.
54
-
55
- ```js
56
- const fn = match("/users{/:id}/delete");
57
-
58
- fn("/users/delete");
59
- //=> { path: '/users/delete', params: {} }
60
-
61
- fn("/users/123/delete");
62
- //=> { path: '/users/123/delete', params: { id: '123' } }
63
- ```
64
-
65
- ## Match
66
-
67
- The `match` function returns a function for matching strings against a path:
68
-
69
- - **path** String or array of strings.
70
- - **options** _(optional)_ (Extends [pathToRegexp](#pathToRegexp) options)
71
- - **decode** Function for decoding strings to params, or `false` to disable all processing. (default: `decodeURIComponent`)
72
-
73
- ```js
74
- const fn = match("/foo/:bar");
75
- ```
76
-
77
- **Please note:** `path-to-regexp` is intended for ordered data (e.g. paths, hosts). It can not handle arbitrarily ordered data (e.g. query strings, URL fragments, JSON, etc).
78
-
79
- ## PathToRegexp
80
-
81
- The `pathToRegexp` function returns a regular expression for matching strings against paths. It
82
-
83
- - **path** String or array of strings.
84
- - **options** _(optional)_ (See [parse](#parse) for more options)
85
- - **sensitive** Regexp will be case sensitive. (default: `false`)
86
- - **end** Validate the match reaches the end of the string. (default: `true`)
87
- - **delimiter** The default delimiter for segments, e.g. `[^/]` for `:named` parameters. (default: `'/'`)
88
- - **trailing** Allows optional trailing delimiter to match. (default: `true`)
89
-
90
- ```js
91
- const { regexp, keys } = pathToRegexp("/foo/:bar");
92
- ```
93
-
94
- ## Compile ("Reverse" Path-To-RegExp)
95
-
96
- The `compile` function will return a function for transforming parameters into a valid path:
97
-
98
- - **path** A string.
99
- - **options** (See [parse](#parse) for more options)
100
- - **delimiter** The default delimiter for segments, e.g. `[^/]` for `:named` parameters. (default: `'/'`)
101
- - **encode** Function for encoding input strings for output into the path, or `false` to disable entirely. (default: `encodeURIComponent`)
102
-
103
- ```js
104
- const toPath = compile("/user/:id");
105
-
106
- toPath({ id: "name" }); //=> "/user/name"
107
- toPath({ id: "café" }); //=> "/user/caf%C3%A9"
108
-
109
- const toPathRepeated = compile("/*segment");
110
-
111
- toPathRepeated({ segment: ["foo"] }); //=> "/foo"
112
- toPathRepeated({ segment: ["a", "b", "c"] }); //=> "/a/b/c"
113
-
114
- // When disabling `encode`, you need to make sure inputs are encoded correctly. No arrays are accepted.
115
- const toPathRaw = compile("/user/:id", { encode: false });
116
-
117
- toPathRaw({ id: "%3A%2F" }); //=> "/user/%3A%2F"
118
- ```
119
-
120
- ## Stringify
121
-
122
- Transform `TokenData` (a sequence of tokens) back into a Path-to-RegExp string.
123
-
124
- - **data** A `TokenData` instance
125
-
126
- ```js
127
- const data = new TokenData([
128
- { type: "text", value: "/" },
129
- { type: "param", name: "foo" },
130
- ]);
131
-
132
- const path = stringify(data); //=> "/:foo"
133
- ```
134
-
135
- ## Developers
136
-
137
- - If you are rewriting paths with match and compile, consider using `encode: false` and `decode: false` to keep raw paths passed around.
138
- - To ensure matches work on paths containing characters usually encoded, such as emoji, consider using [encodeurl](https://github.com/pillarjs/encodeurl) for `encodePath`.
139
-
140
- ### Parse
141
-
142
- The `parse` function accepts a string and returns `TokenData`, the set of tokens and other metadata parsed from the input string. `TokenData` is can used with `match` and `compile`.
143
-
144
- - **path** A string.
145
- - **options** _(optional)_
146
- - **encodePath** A function for encoding input strings. (default: `x => x`, recommended: [`encodeurl`](https://github.com/pillarjs/encodeurl))
147
-
148
- ### Tokens
149
-
150
- `TokenData` is a sequence of tokens, currently of types `text`, `parameter`, `wildcard`, or `group`.
151
-
152
- ### Custom path
153
-
154
- In some applications, you may not be able to use the `path-to-regexp` syntax, but still want to use this library for `match` and `compile`. For example:
155
-
156
- ```js
157
- import { TokenData, match } from "path-to-regexp";
158
-
159
- const tokens = [
160
- { type: "text", value: "/" },
161
- { type: "parameter", name: "foo" },
162
- ];
163
- const path = new TokenData(tokens);
164
- const fn = match(path);
165
-
166
- fn("/test"); //=> { path: '/test', index: 0, params: { foo: 'test' } }
167
- ```
168
-
169
- ## Errors
170
-
171
- 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.
172
-
173
- ### Unexpected `?` or `+`
174
-
175
- In past releases, `?`, `*`, and `+` were used to denote optional or repeating parameters. As an alternative, try these:
176
-
177
- - For optional (`?`), use an empty segment in a group such as `/:file{.:ext}`.
178
- - For repeating (`+`), only wildcard matching is supported, such as `/*path`.
179
- - For optional repeating (`*`), use a group and a wildcard parameter such as `/files{/*path}`.
180
-
181
- ### Unexpected `(`, `)`, `[`, `]`, etc.
182
-
183
- 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 use these characters literally, escape them with a backslash, e.g. `"\\("`.
184
-
185
- ### Missing parameter name
186
-
187
- Parameter names must be provided after `:` or `*`, and they must be a valid JavaScript identifier. If you want an parameter name that isn't a JavaScript identifier, such as starting with a number, you can wrap the name in quotes like `:"my-name"`.
188
-
189
- ### Unterminated quote
190
-
191
- Parameter names can be wrapped in double quote characters, and this error means you forgot to close the quote character.
192
-
193
- ### Express <= 4.x
194
-
195
- Path-To-RegExp breaks compatibility with Express <= `4.x` in the following ways:
196
-
197
- - The wildcard `*` must have a name, matching the behavior of parameters `:`.
198
- - The optional character `?` is no longer supported, use braces instead: `/:file{.:ext}`.
199
- - Regexp characters are not supported.
200
- - Some characters have been reserved to avoid confusion during upgrade (`()[]?+!`).
201
- - Parameter names now support valid JavaScript identifiers, or quoted like `:"this"`.
202
-
203
- ## License
204
-
205
- MIT
206
-
207
- [npm-image]: https://img.shields.io/npm/v/path-to-regexp
208
- [npm-url]: https://npmjs.org/package/path-to-regexp
209
- [downloads-image]: https://img.shields.io/npm/dm/path-to-regexp
210
- [downloads-url]: https://npmjs.org/package/path-to-regexp
211
- [build-image]: https://img.shields.io/github/actions/workflow/status/pillarjs/path-to-regexp/ci.yml?branch=master
212
- [build-url]: https://github.com/pillarjs/path-to-regexp/actions/workflows/ci.yml?query=branch%3Amaster
213
- [coverage-image]: https://img.shields.io/codecov/c/gh/pillarjs/path-to-regexp
214
- [coverage-url]: https://codecov.io/gh/pillarjs/path-to-regexp
215
- [license-image]: http://img.shields.io/npm/l/path-to-regexp.svg?style=flat
216
- [license-url]: LICENSE.md