From f712c05b830040458087eb3eb947b36e28047861 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 21 Dec 2021 10:27:06 -0800 Subject: [PATCH] url: add experimental URLPattern Signed-off-by: James M Snell --- doc/api/url.md | 174 ++++ lib/internal/urlpattern.js | 1335 ++++++++++++++++++++++++++++++ lib/url.js | 4 + test/parallel/test-urlpattern.js | 458 ++++++++++ tools/doc/type-parser.mjs | 4 + 5 files changed, 1975 insertions(+) create mode 100644 lib/internal/urlpattern.js create mode 100644 test/parallel/test-urlpattern.js diff --git a/doc/api/url.md b/doc/api/url.md index 3fa589397f77d6..60764106ef21fd 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -1277,6 +1277,180 @@ console.log(urlToHttpOptions(myUrl)); */ ``` +## URLPattern + +The `URLPattern` is a Web Platform API for matching URLs against a pattern +syntax. + +### Class: `URLPattern` + + + +#### `new URLPattern([input[, baseURL]])` + + + +* `input` {string|URLPatternInit} +* `baseURL` {string} + +Create a new `URLPattern`. + +#### `urlPattern.exec([input[, baseURL]])` + + + +* `input` {string|URLPatternInit} +* `baseURL` {string} +* Returns: {URLPatternResult|null} + +Executes this `URLPattern` against the given `input`, returning an +{URLPatternResult} that contains each of the matching components if +the pattern matches the input, or `null` if the pattern does not match. + +#### `urlPattern.hash` + + + +* Type: {string} The pattern string the pattern will use to match a URLs + hash fragment component. + +#### `urlPattern.hostname` + + + +* Type: {string} The pattern string the pattern will use to match a URLs + hostname component. + +#### `urlPattern.password` + + + +* Type: {string} The pattern string the pattern will use to match a URLs + password component. + +#### `urlPattern.pathname` + + + +* Type: {string} The pattern string the pattern will use to match a URLs + pathname component. + +#### `urlPattern.port` + + + +* Type: {string} The pattern string the pattern will use to match a URLs + port component. + +#### `urlPattern.protocol` + + + +* Type: {string} The pattern string the pattern will use to match a URLs + protocol scheme component. + +#### `urlPattern.search` + + + +* Type: {string} The pattern string the pattern will use to match a URLs + querystring component. + +#### `urlPattern.test([input[, baseURL]])` + + + +* `input` {string|URLPatternInit} +* `baseURL` {string} +* Returns: {boolean} + +Returns `true` if the `input` matches this `URLPattern`. + +#### `urlPattern.username` + + + +* Type: {string} The pattern string the pattern will use to match a URLs + username component. + +### Object: `URLPatternInit` + + + +A `URLPatternInit` is a regular JavaScript object with zero or more of the +following property attributes that provide patterns for each of the individual +URL components: + +* `protocol` {string} +* `username` {string} +* `password` {string} +* `hostname` {string} +* `port` {string} +* `pathname` {string} +* `search` {string} +* `hash` {string} +* `baseURL` {string} + +### Object: `URLPatternResult` + + + +A `URLPatternResult` object is returned by the `urlPattern.exec()` method and +provides details on the matching components of the `input`. + +* `inputs` {string[]|URLPatternInit[]} +* `protocol` {URLPatternComponentResult} +* `username` {URLPatternComponentResult} +* `password` {URLPatternComponentResult} +* `hostname` {URLPatternComponentResult} +* `port` {URLPatternComponentResult} +* `pathname` {URLPatternComponentResult} +* `search` {URLPatternComponentResult} +* `hash` {URLPatternComponentResult} + +### Object: `URLPatternComponentResult` + + + +A `URLPatternComponentResult` is a regular JavaScript object that contains +matching information for an individual URL component. + +* `input` {string} The input string that was matched against. +* `groups` {Object} A JavaScript object containing one or more + key and value pairs detailing the relevant matches for the component. + The specific keys will depend on the structure the `URLPattern` and + the matching input. Keys and values will always be strings. + ## Legacy URL API