Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2021-03-20 00:43:18 +0300
committerRuy Adorno <ruyadorno@hotmail.com>2021-03-24 04:17:30 +0300
commit30bc2e43e47499a93447e73c6befd9d0521f3cc2 (patch)
tree6ea4002211b9396fe4ecea598ec21e874dbbfb62
parent5d4c6107277e399abc593295a7f9315d4544ce4e (diff)
doc: add examples for WHATWG URL objects
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/37822 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
-rw-r--r--doc/api/url.md25
1 files changed, 25 insertions, 0 deletions
diff --git a/doc/api/url.md b/doc/api/url.md
index f93cf741473..8ad7c5eed50 100644
--- a/doc/api/url.md
+++ b/doc/api/url.md
@@ -67,6 +67,31 @@ const myURL =
url.parse('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash');
```
+### Constructing a URL from component parts and getting the constructed string
+
+It is possible to construct a WHATWG URL from component parts using either the
+property setters or a template literal string:
+
+```js
+const myURL = new URL('https://example.org');
+myURL.pathname = '/a/b/c';
+myURL.search = '?d=e';
+myURL.hash = '#fgh';
+```
+
+```js
+const pathname = '/a/b/c';
+const search = '?d=e';
+const hash = '#fgh';
+const myURL = new URL(`https://example.org${pathname}${search}${hash}`);
+```
+
+To get the constructed URL string, use the `href` property accessor:
+
+```js
+console.log(myURL.href);
+```
+
## The WHATWG URL API
### Class: `URL`