@@ -131,6 +131,50 @@ The `slashes` property is a `boolean` with a value of `true` if two ASCII
131
131
forward-slash characters (` / ` ) are required following the colon in the
132
132
` protocol ` .
133
133
134
+ ## url.domainToASCII(domain)
135
+
136
+ > Stability: 1 - Experimental
137
+
138
+ * ` domain ` {string}
139
+ * Returns: {string}
140
+
141
+ Returns the [ Punycode] [ ] ASCII serialization of the ` domain ` . If ` domain ` is an
142
+ invalid domain, the empty string is returned.
143
+
144
+ It performs the inverse operation to [ ` url.domainToUnicode() ` ] [ ] .
145
+
146
+ ``` js
147
+ const url = require (' url' );
148
+ console .log (url .domainToASCII (' español.com' ));
149
+ // Prints xn--espaol-zwa.com
150
+ console .log (url .domainToASCII (' 中文.com' ));
151
+ // Prints xn--fiq228c.com
152
+ console .log (url .domainToASCII (' xn--iñvalid.com' ));
153
+ // Prints an empty string
154
+ ```
155
+
156
+ ## url.domainToUnicode(domain)
157
+
158
+ > Stability: 1 - Experimental
159
+
160
+ * ` domain ` {string}
161
+ * Returns: {string}
162
+
163
+ Returns the Unicode serialization of the ` domain ` . If ` domain ` is an invalid
164
+ domain, the empty string is returned.
165
+
166
+ It performs the inverse operation to [ ` url.domainToASCII() ` ] [ ] .
167
+
168
+ ``` js
169
+ const url = require (' url' );
170
+ console .log (url .domainToUnicode (' xn--espaol-zwa.com' ));
171
+ // Prints español.com
172
+ console .log (url .domainToUnicode (' xn--fiq228c.com' ));
173
+ // Prints 中文.com
174
+ console .log (url .domainToUnicode (' xn--iñvalid.com' ));
175
+ // Prints an empty string
176
+ ```
177
+
134
178
## url.format(urlObject)
135
179
<!-- YAML
136
180
added: v0.1.25
@@ -993,52 +1037,6 @@ for (const [name, value] of params) {
993
1037
// xyz baz
994
1038
```
995
1039
996
- ### require('url').domainToASCII(domain)
997
-
998
- * ` domain ` {string}
999
- * Returns: {string}
1000
-
1001
- Returns the [ Punycode] [ ] ASCII serialization of the ` domain ` . If ` domain ` is an
1002
- invalid domain, the empty string is returned.
1003
-
1004
- It performs the inverse operation to [ ` require('url').domainToUnicode() ` ] [ ] .
1005
-
1006
- ``` js
1007
- const url = require (' url' );
1008
- console .log (url .domainToASCII (' español.com' ));
1009
- // Prints xn--espaol-zwa.com
1010
- console .log (url .domainToASCII (' 中文.com' ));
1011
- // Prints xn--fiq228c.com
1012
- console .log (url .domainToASCII (' xn--iñvalid.com' ));
1013
- // Prints an empty string
1014
- ```
1015
-
1016
- * Note* : The ` require('url').domainToASCII() ` method is introduced as part of
1017
- the new ` URL ` implementation but is not part of the WHATWG URL standard.
1018
-
1019
- ### require('url').domainToUnicode(domain)
1020
-
1021
- * ` domain ` {string}
1022
- * Returns: {string}
1023
-
1024
- Returns the Unicode serialization of the ` domain ` . If ` domain ` is an invalid
1025
- domain, the empty string is returned.
1026
-
1027
- It performs the inverse operation to [ ` require('url').domainToASCII() ` ] [ ] .
1028
-
1029
- ``` js
1030
- const url = require (' url' );
1031
- console .log (url .domainToUnicode (' xn--espaol-zwa.com' ));
1032
- // Prints español.com
1033
- console .log (url .domainToUnicode (' xn--fiq228c.com' ));
1034
- // Prints 中文.com
1035
- console .log (url .domainToUnicode (' xn--iñvalid.com' ));
1036
- // Prints an empty string
1037
- ```
1038
-
1039
- * Note* : The ` require('url').domainToUnicode() ` API is introduced as part of the
1040
- the new ` URL ` implementation but is not part of the WHATWG URL standard.
1041
-
1042
1040
<a id =" whatwg-percent-encoding " ></a >
1043
1041
### Percent-Encoding in the WHATWG URL Standard
1044
1042
@@ -1088,6 +1086,8 @@ console.log(myURL.origin);
1088
1086
[ `TypeError` ] : errors.html#errors_class_typeerror
1089
1087
[ WHATWG URL Standard ] : https://url.spec.whatwg.org/
1090
1088
[ examples of parsed URLs ] : https://url.spec.whatwg.org/#example-url-parsing
1089
+ [ `url.domainToASCII()` ] : #url_url_domaintoascii_domain
1090
+ [ `url.domainToUnicode()` ] : #url_url_domaintounicode_domain
1091
1091
[ `url.parse()` ] : #url_url_parse_urlstring_parsequerystring_slashesdenotehost
1092
1092
[ `url.format()` ] : #url_url_format_urlobject
1093
1093
[ `require('url').format()` ] : #url_url_format_url_options
@@ -1103,8 +1103,6 @@ console.log(myURL.origin);
1103
1103
[ `URLSearchParams` ] : #url_class_urlsearchparams
1104
1104
[ `urlSearchParams.entries()` ] : #url_urlsearchparams_entries
1105
1105
[ `urlSearchParams@@iterator()` ] : #url_urlsearchparams_iterator
1106
- [ `require('url').domainToASCII()` ] : #url_require_url_domaintoascii_domain
1107
- [ `require('url').domainToUnicode()` ] : #url_require_url_domaintounicode_domain
1108
1106
[ stable sorting algorithm ] : https://en.wikipedia.org/wiki/Sorting_algorithm#Stability
1109
1107
[ `JSON.stringify()` ] : https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
1110
1108
[ `url.toJSON()` ] : #url_url_tojson
0 commit comments