@@ -992,22 +992,48 @@ for (const [name, value] of params) {
992
992
// xyz baz
993
993
```
994
994
995
- ### require('url').domainToAscii (domain)
995
+ ### require('url').domainToASCII (domain)
996
996
997
997
* ` domain ` {String}
998
998
* Returns: {String}
999
999
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.
1001
1002
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
1003
1016
the new ` URL ` implementation but is not part of the WHATWG URL standard.
1004
1017
1005
1018
### require('url').domainToUnicode(domain)
1006
1019
1007
1020
* ` domain ` {String}
1008
1021
* Returns: {String}
1009
1022
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
+ ```
1011
1037
1012
1038
* Note* : The ` require('url').domainToUnicode() ` API is introduced as part of the
1013
1039
the new ` URL ` implementation but is not part of the WHATWG URL standard.
@@ -1074,6 +1100,8 @@ console.log(myURL.origin);
1074
1100
[ `URLSearchParams` ] : #url_class_urlsearchparams
1075
1101
[ `urlSearchParams.entries()` ] : #url_urlsearchparams_entries
1076
1102
[ `urlSearchParams@@iterator()` ] : #url_urlsearchparams_iterator
1103
+ [ `require('url').domainToASCII()` ] : #url_require_url_domaintoascii_domain
1104
+ [ `require('url').domainToUnicode()` ] : #url_require_url_domaintounicode_domain
1077
1105
[ stable sorting algorithm ] : https://en.wikipedia.org/wiki/Sorting_algorithm#Stability
1078
1106
[ `JSON.stringify()` ] : https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
1079
1107
[ `url.toJSON()` ] : #url_url_tojson
0 commit comments