From 1572a5b6cd16aeb6cafd338814ead76c0f198f1d Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Tue, 20 Feb 2018 12:10:54 -0800 Subject: doc: add URL.format() example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/18888 Fixes: https://github.com/nodejs/node/issues/18887 Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Rich Trott Reviewed-By: Ruben Bridgewater Reviewed-By: Vse Mozhet Byt Reviewed-By: Colin Ihrig Reviewed-By: Roman Reiss Reviewed-By: Daijiro Wachi Reviewed-By: Tobias Nießen --- doc/api/url.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'doc/api/url.md') diff --git a/doc/api/url.md b/doc/api/url.md index 843c4b5446..2c12e9ac29 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -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`][]. -- cgit v1.2.3