From c14b2960f39de58211a61ac7d30712e05556dd37 Mon Sep 17 00:00:00 2001 From: Nicolas Charpentier Date: Fri, 4 Sep 2026 19:59:38 -0400 Subject: [PATCH] doc: document URLPattern instance getters `URLPattern` instances expose the `protocol`, `username`, `password`, `hostname`, `port`, `pathname`, `search` and `hash` getters, which return the pattern string of each component, and the `hasRegExpGroups` getter. They have been available since the initial implementation but were never documented. Refs: https://urlpattern.spec.whatwg.org/#dom-urlpattern-protocol Refs: https://urlpattern.spec.whatwg.org/#dom-urlpattern-hasregexpgroups --- doc/api/url.md | 157 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) diff --git a/doc/api/url.md b/doc/api/url.md index 7759c03a15e7..8a6ce4edc4c3 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -792,6 +792,163 @@ case-insensitive matching if set to true. The constructor can throw a `TypeError` to indicate parsing failure. +#### `urlPattern.hash` + + + +* Type: {string} + +Gets the read-only pattern string of the URL pattern's `hash` component. +In this example the pattern does not specify a hash component, so it matches +any value and the pattern string is the wildcard `'*'`. + +```js +const myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html'); +console.log(myPattern.hash); +// Prints: * +``` + +#### `urlPattern.hasRegExpGroups` + + + +* Type: {boolean} + +Gets a read-only boolean that is `true` if any component of the URL pattern +contains a regular expression group, and `false` otherwise. + +```js +const bookPattern = new URLPattern({ pathname: '/books/:id' }); +console.log(bookPattern.hasRegExpGroups); +// Prints: false + +const versionPattern = new URLPattern({ pathname: '/docs/:version(v\\d+)/*' }); +console.log(versionPattern.hasRegExpGroups); +// Prints: true +``` + +#### `urlPattern.hostname` + + + +* Type: {string} + +Gets the read-only pattern string of the URL pattern's `hostname` component. + +```js +const myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html'); +console.log(myPattern.hostname); +// Prints: nodejs.org +``` + +#### `urlPattern.password` + + + +* Type: {string} + +Gets the read-only pattern string of the URL pattern's `password` component. +In this example the pattern does not specify a password component, so it matches +any value and the pattern string is the wildcard `'*'`. + +```js +const myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html'); +console.log(myPattern.password); +// Prints: * +``` + +#### `urlPattern.pathname` + + + +* Type: {string} + +Gets the read-only pattern string of the URL pattern's `pathname` component. + +```js +const myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html'); +console.log(myPattern.pathname); +// Prints: /docs/latest/api/*.html +``` + +#### `urlPattern.port` + + + +* Type: {string} + +Gets the read-only pattern string of the URL pattern's `port` component. + +```js +const myPattern = new URLPattern('https://nodejs.org:8080/docs/*'); +console.log(myPattern.port); +// Prints: 8080 +``` + +#### `urlPattern.protocol` + + + +* Type: {string} + +Gets the read-only pattern string of the URL pattern's `protocol` component. + +```js +const myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html'); +console.log(myPattern.protocol); +// Prints: https +``` + +#### `urlPattern.search` + + + +* Type: {string} + +Gets the read-only pattern string of the URL pattern's `search` component. +In this example the pattern does not specify a search component, so it matches +any value and the pattern string is the wildcard `'*'`. + +```js +const myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html'); +console.log(myPattern.search); +// Prints: * +``` + +#### `urlPattern.username` + + + +* Type: {string} + +Gets the read-only pattern string of the URL pattern's `username` component. +In this example the pattern does not specify a username component, so it matches +any value and the pattern string is the wildcard `'*'`. + +```js +const myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html'); +console.log(myPattern.username); +// Prints: * +``` + #### `urlPattern.exec(input[, baseURL])` * `input` {string | Object} A URL or URL parts