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
path: root/doc
diff options
context:
space:
mode:
authorZeke Sikelianos <zeke@sikelianos.com>2018-02-20 23:10:54 +0300
committerMyles Borins <mylesborins@google.com>2018-09-06 19:40:50 +0300
commitd9895c4ba7d49477954da02c362c7b03509a30bd (patch)
treef9429148d2a46f8bcec1b0a37cd5a593e9286275 /doc
parentc2978ac0454fe68594978db7e6012d8417c76c25 (diff)
doc: add URL.format() example
Backport-PR-URL: https://github.com/nodejs/node/pull/22380 PR-URL: https://github.com/nodejs/node/pull/18888 Fixes: https://github.com/nodejs/node/issues/18887 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/url.md14
1 files changed, 14 insertions, 0 deletions
diff --git a/doc/api/url.md b/doc/api/url.md
index 55649313b3a..4d7fb9c8f45 100644
--- a/doc/api/url.md
+++ b/doc/api/url.md
@@ -971,6 +971,20 @@ changes:
The `url.format()` method returns a formatted URL string derived from
`urlObject`.
+```js
+url.format({
+ protocol: 'https',
+ hostname: 'example.com',
+ pathname: '/some/path',
+ query: {
+ page: 1,
+ format: 'json'
+ }
+});
+
+// => 'https://example.com/some/path?page=1&format=json'
+```
+
If `urlObject` is not an object or a string, `url.format()` will throw a
[`TypeError`][].