@@ -876,22 +876,48 @@ for (const [name, value] of params) {
876
876
// xyz baz
877
877
```
878
878
879
- ### require('url').domainToAscii (domain)
879
+ ### require('url').domainToASCII (domain)
880
880
881
881
* ` domain ` {String}
882
882
* Returns: {String}
883
883
884
- Returns the [ Punycode] [ ] ASCII serialization of the ` domain ` .
884
+ Returns the [ Punycode] [ ] ASCII serialization of the ` domain ` . If ` domain ` is an
885
+ invalid domain, the empty string is returned.
885
886
886
- * Note* : The ` require('url').domainToAscii() ` method is introduced as part of
887
+ It performs the inverse operation to [ ` require('url').domainToUnicode() ` ] [ ] .
888
+
889
+ ``` js
890
+ const url = require (' url' );
891
+ console .log (url .domainToASCII (' español.com' ));
892
+ // Prints xn--espaol-zwa.com
893
+ console .log (url .domainToASCII (' 中文.com' ));
894
+ // Prints xn--fiq228c.com
895
+ console .log (url .domainToASCII (' xn--iñvalid.com' ));
896
+ // Prints an empty string
897
+ ```
898
+
899
+ * Note* : The ` require('url').domainToASCII() ` method is introduced as part of
887
900
the new ` URL ` implementation but is not part of the WHATWG URL standard.
888
901
889
902
### require('url').domainToUnicode(domain)
890
903
891
904
* ` domain ` {String}
892
905
* Returns: {String}
893
906
894
- Returns the Unicode serialization of the ` domain ` .
907
+ Returns the Unicode serialization of the ` domain ` . If ` domain ` is an invalid
908
+ domain, the empty string is returned.
909
+
910
+ It performs the inverse operation to [ ` require('url').domainToASCII() ` ] [ ] .
911
+
912
+ ``` js
913
+ const url = require (' url' );
914
+ console .log (url .domainToUnicode (' xn--espaol-zwa.com' ));
915
+ // Prints español.com
916
+ console .log (url .domainToUnicode (' xn--fiq228c.com' ));
917
+ // Prints 中文.com
918
+ console .log (url .domainToUnicode (' xn--iñvalid.com' ));
919
+ // Prints an empty string
920
+ ```
895
921
896
922
* Note* : The ` require('url').domainToUnicode() ` API is introduced as part of the
897
923
the new ` URL ` implementation but is not part of the WHATWG URL standard.
@@ -956,6 +982,8 @@ console.log(myURL.origin);
956
982
[ `URLSearchParams` ] : #url_class_urlsearchparams
957
983
[ `urlSearchParams.entries()` ] : #url_urlsearchparams_entries
958
984
[ `urlSearchParams@@iterator()` ] : #url_urlsearchparams_iterator
985
+ [ `require('url').domainToASCII()` ] : #url_require_url_domaintoascii_domain
986
+ [ `require('url').domainToUnicode()` ] : #url_require_url_domaintounicode_domain
959
987
[ stable sorting algorithm ] : https://en.wikipedia.org/wiki/Sorting_algorithm#Stability
960
988
[ `JSON.stringify()` ] : https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
961
989
[ `url.toJSON()` ] : #url_url_tojson
0 commit comments