Skip to content

Commit a0742f3

Browse files
zekeMayaLekova
authored andcommitted
doc: add URL.format() example
PR-URL: nodejs#18888 Fixes: nodejs#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>
1 parent 2bd98db commit a0742f3

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

doc/api/url.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,20 @@ changes:
948948
The `url.format()` method returns a formatted URL string derived from
949949
`urlObject`.
950950

951+
```js
952+
url.format({
953+
protocol: 'https',
954+
hostname: 'example.com',
955+
pathname: '/some/path',
956+
query: {
957+
page: 1,
958+
format: 'json'
959+
}
960+
});
961+
962+
// => 'https://example.com/some/path?page=1&format=json'
963+
```
964+
951965
If `urlObject` is not an object or a string, `url.format()` will throw a
952966
[`TypeError`][].
953967

0 commit comments

Comments
 (0)