Skip to content

Commit 7ceea2a

Browse files
committed
doc: document WHATWG IDNA methods' error handling
PR-URL: #11549 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 6c21397 commit 7ceea2a

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

doc/api/url.md

+32-4
Original file line numberDiff line numberDiff line change
@@ -992,22 +992,48 @@ for (const [name, value] of params) {
992992
// xyz baz
993993
```
994994

995-
### require('url').domainToAscii(domain)
995+
### require('url').domainToASCII(domain)
996996

997997
* `domain` {String}
998998
* Returns: {String}
999999

1000-
Returns the [Punycode][] ASCII serialization of the `domain`.
1000+
Returns the [Punycode][] ASCII serialization of the `domain`. If `domain` is an
1001+
invalid domain, the empty string is returned.
10011002

1002-
*Note*: The `require('url').domainToAscii()` method is introduced as part of
1003+
It performs the inverse operation to [`require('url').domainToUnicode()`][].
1004+
1005+
```js
1006+
const url = require('url');
1007+
console.log(url.domainToASCII('español.com'));
1008+
// Prints xn--espaol-zwa.com
1009+
console.log(url.domainToASCII('中文.com'));
1010+
// Prints xn--fiq228c.com
1011+
console.log(url.domainToASCII('xn--iñvalid.com'));
1012+
// Prints an empty string
1013+
```
1014+
1015+
*Note*: The `require('url').domainToASCII()` method is introduced as part of
10031016
the new `URL` implementation but is not part of the WHATWG URL standard.
10041017

10051018
### require('url').domainToUnicode(domain)
10061019

10071020
* `domain` {String}
10081021
* Returns: {String}
10091022

1010-
Returns the Unicode serialization of the `domain`.
1023+
Returns the Unicode serialization of the `domain`. If `domain` is an invalid
1024+
domain, the empty string is returned.
1025+
1026+
It performs the inverse operation to [`require('url').domainToASCII()`][].
1027+
1028+
```js
1029+
const url = require('url');
1030+
console.log(url.domainToUnicode('xn--espaol-zwa.com'));
1031+
// Prints español.com
1032+
console.log(url.domainToUnicode('xn--fiq228c.com'));
1033+
// Prints 中文.com
1034+
console.log(url.domainToUnicode('xn--iñvalid.com'));
1035+
// Prints an empty string
1036+
```
10111037

10121038
*Note*: The `require('url').domainToUnicode()` API is introduced as part of the
10131039
the new `URL` implementation but is not part of the WHATWG URL standard.
@@ -1074,6 +1100,8 @@ console.log(myURL.origin);
10741100
[`URLSearchParams`]: #url_class_urlsearchparams
10751101
[`urlSearchParams.entries()`]: #url_urlsearchparams_entries
10761102
[`urlSearchParams@@iterator()`]: #url_urlsearchparams_iterator
1103+
[`require('url').domainToASCII()`]: #url_require_url_domaintoascii_domain
1104+
[`require('url').domainToUnicode()`]: #url_require_url_domaintounicode_domain
10771105
[stable sorting algorithm]: https://en.wikipedia.org/wiki/Sorting_algorithm#Stability
10781106
[`JSON.stringify()`]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
10791107
[`url.toJSON()`]: #url_url_tojson

0 commit comments

Comments
 (0)