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:
Zeke Sikelianos 2018-02-20 12:10:54 -08:00 committed by Anatoli Papirovski
parent a865e8ba67
commit 1572a5b6cd
No known key found for this signature in database
GPG Key ID: 614E2E1ABEB4B2C0

View File

@ -948,6 +948,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`][].