doc: add URL.format() example
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>
This commit is contained in:
parent
a865e8ba67
commit
1572a5b6cd
@ -948,6 +948,20 @@ changes:
|
|||||||
The `url.format()` method returns a formatted URL string derived from
|
The `url.format()` method returns a formatted URL string derived from
|
||||||
`urlObject`.
|
`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
|
If `urlObject` is not an object or a string, `url.format()` will throw a
|
||||||
[`TypeError`][].
|
[`TypeError`][].
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user