@@ -198,6 +198,47 @@ The formatting process operates as follows:
198198 string, an [ ` Error ` ] [ ] is thrown.
199199* ` result ` is returned.
200200
201+ ## url.format(URL[ , options] )
202+
203+ > Stability: 1 - Experimental
204+
205+ * ` URL ` {URL} A [ WHATWG URL] [ ] object
206+ * ` options ` {Object}
207+ * ` auth ` {Boolean} ` true ` if the serialized URL string should include the
208+ username and password, ` false ` otherwise. Defaults to ` true ` .
209+ * ` fragment ` {Boolean} ` true ` if the serialized URL string should include the
210+ fragment, ` false ` otherwise. Defaults to ` true ` .
211+ * ` search ` {Boolean} ` true ` if the serialized URL string should include the
212+ search query, ` false ` otherwise. Defaults to ` true ` .
213+ * ` unicode ` (Boolean) ` true ` if Unicode characters appearing in the host
214+ component of the URL string should be encoded directly as opposed to being
215+ Punycode encoded. Defaults to ` false ` .
216+
217+ Returns a customizable serialization of a URL String representation of a
218+ [ WHATWG URL] [ ] object.
219+
220+ The URL object has both a ` toString() ` method and ` href ` property that return
221+ string serializations of the URL. These are not, however, customizable in
222+ any way. The ` url.format(URL[, options]) ` method allows for basic customization
223+ of the output.
224+
225+ For example:
226+
227+ ``` js
228+ const myURL = new URL (' https://a:b@你好你好?abc#foo' );
229+
230+ console .log (myURL .href );
231+ // Prints https://a:b@xn--6qqa088eba/?abc#foo
232+
233+ console .log (myURL .toString ());
234+ // Prints https://a:b@xn--6qqa088eba/?abc#foo
235+
236+ console .log (url .format (myURL, {fragment: false , unicode: true , auth: false }));
237+ // Prints 'https://你好你好?abc'
238+ ```
239+
240+ * Note* : This variation of the ` url.format() ` method is currently considered to
241+ be experimental.
201242
202243## url.parse(urlString[ , parseQueryString[ , slashesDenoteHost]] )
203244<!-- YAML
@@ -712,3 +753,4 @@ console.log(myURL.origin);
712753[ `url.parse()` ] : #url_url_parse_urlstring_parsequerystring_slashesdenotehost
713754[ `url.format()` ] : #url_url_format_urlobject
714755[ Punycode ] : https://tools.ietf.org/html/rfc5891#section-4.4
756+ [ WHATWG URL ] : #url_the_whatwg_url_api
0 commit comments