@@ -26,47 +26,47 @@ backwards compatibility with existing applications. New application code
2626should use the WHATWG API.
2727
2828A comparison between the WHATWG and Legacy APIs is provided below. Above the URL
29- ` 'http://user:pass@sub.host .com:8080/p/a/t/h?query=string#hash' ` , properties of
30- an object returned by the legacy ` url.parse() ` are shown. Below it are
29+ ` 'http://user:pass@sub.example .com:8080/p/a/t/h?query=string#hash' ` , properties
30+ of an object returned by the legacy ` url.parse() ` are shown. Below it are
3131properties of a WHATWG ` URL ` object.
3232
3333WHATWG URL's ` origin ` property includes ` protocol ` and ` host ` , but not
3434` username ` or ` password ` .
3535
3636``` txt
37- ┌─────────────────────────────────────────────────────────────────────────────────────────────┐
38- │ href │
39- ├──────────┬──┬─────────────────────┬─────────────────────┬───────────────────────────┬───────┤
40- │ protocol │ │ auth │ host │ path │ hash │
41- │ │ │ ├──────────────┬──────┼──────────┬────────────────┤ │
42- │ │ │ │ hostname │ port │ pathname │ search │ │
43- │ │ │ │ │ │ ├─┬──────────────┤ │
44- │ │ │ │ │ │ │ │ query │ │
45- " https: // user : pass @ sub.host .com : 8080 /p/a/t/h ? query=string #hash "
46- │ │ │ │ │ hostname │ port │ │ │ │
47- │ │ │ │ ├──────────────┴──────┤ │ │ │
48- │ protocol │ │ username │ password │ host │ │ │ │
49- ├──────────┴──┼──────────┴──────────┼─────────────────────┤ │ │ │
50- │ origin │ │ origin │ pathname │ search │ hash │
51- ├─────────────┴─────────────────────┴─────────────────────┴──────────┴────────────────┴───────┤
52- │ href │
53- └─────────────────────────────────────────────────────────────────────────────────────────────┘
37+ ┌──────────────────────────────────────────────────────────────────────────────────────────────── ┐
38+ │ href │
39+ ├──────────┬──┬─────────────────────┬──────────────────────── ┬───────────────────────────┬───────┤
40+ │ protocol │ │ auth │ host │ path │ hash │
41+ │ │ │ ├───────────────── ┬──────┼──────────┬────────────────┤ │
42+ │ │ │ │ hostname │ port │ pathname │ search │ │
43+ │ │ │ │ │ │ ├─┬──────────────┤ │
44+ │ │ │ │ │ │ │ │ query │ │
45+ " https: // user : pass @ sub.example .com : 8080 /p/a/t/h ? query=string #hash "
46+ │ │ │ │ │ hostname │ port │ │ │ │
47+ │ │ │ │ ├───────────────── ┴──────┤ │ │ │
48+ │ protocol │ │ username │ password │ host │ │ │ │
49+ ├──────────┴──┼──────────┴──────────┼──────────────────────── ┤ │ │ │
50+ │ origin │ │ origin │ pathname │ search │ hash │
51+ ├─────────────┴─────────────────────┴──────────────────────── ┴──────────┴────────────────┴───────┤
52+ │ href │
53+ └──────────────────────────────────────────────────────────────────────────────────────────────── ┘
5454(all spaces in the "" line should be ignored — they are purely for formatting)
5555```
5656
5757Parsing the URL string using the WHATWG API:
5858
5959``` js
6060const myURL =
61- new URL (' https://user:pass@sub.host .com:8080/p/a/t/h?query=string#hash' );
61+ new URL (' https://user:pass@sub.example .com:8080/p/a/t/h?query=string#hash' );
6262```
6363
6464Parsing the URL string using the Legacy API:
6565
6666``` js
6767const url = require (' url' );
6868const myURL =
69- url .parse (' https://user:pass@sub.host .com:8080/p/a/t/h?query=string#hash' );
69+ url .parse (' https://user:pass@sub.example .com:8080/p/a/t/h?query=string#hash' );
7070```
7171
7272## The WHATWG URL API
@@ -120,8 +120,8 @@ Unicode characters appearing within the hostname of `input` will be
120120automatically converted to ASCII using the [ Punycode] [ ] algorithm.
121121
122122``` js
123- const myURL = new URL (' https://你好你好 ' );
124- // https://xn--6qqa088eba /
123+ const myURL = new URL (' https://測試 ' );
124+ // https://xn--g6w251d /
125125```
126126
127127This feature is only available if the ` node ` executable was compiled with
@@ -132,23 +132,23 @@ and a `base` is provided, it is advised to validate that the `origin` of
132132the ` URL ` object is what is expected.
133133
134134``` js
135- let myURL = new URL (' http://anotherExample.org /' , ' https://example.org/' );
136- // http://anotherexample.org /
135+ let myURL = new URL (' http://Example.com /' , ' https://example.org/' );
136+ // http://example.com /
137137
138- myURL = new URL (' https://anotherExample.org /' , ' https://example.org/' );
139- // https://anotherexample.org /
138+ myURL = new URL (' https://Example.com /' , ' https://example.org/' );
139+ // https://example.com /
140140
141- myURL = new URL (' foo://anotherExample.org /' , ' https://example.org/' );
142- // foo://anotherExample.org /
141+ myURL = new URL (' foo://Example.com /' , ' https://example.org/' );
142+ // foo://Example.com /
143143
144- myURL = new URL (' http:anotherExample.org /' , ' https://example.org/' );
145- // http://anotherexample.org /
144+ myURL = new URL (' http:Example.com /' , ' https://example.org/' );
145+ // http://example.com /
146146
147- myURL = new URL (' https:anotherExample.org /' , ' https://example.org/' );
148- // https://example.org/anotherExample.org /
147+ myURL = new URL (' https:Example.com /' , ' https://example.org/' );
148+ // https://example.org/Example.com /
149149
150- myURL = new URL (' foo:anotherExample.org /' , ' https://example.org/' );
151- // foo:anotherExample.org /
150+ myURL = new URL (' foo:Example.com /' , ' https://example.org/' );
151+ // foo:Example.com /
152152```
153153
154154#### url.hash
@@ -249,12 +249,12 @@ console.log(myURL.origin);
249249```
250250
251251``` js
252- const idnURL = new URL (' https://你好你好 ' );
252+ const idnURL = new URL (' https://測試 ' );
253253console .log (idnURL .origin );
254- // Prints https://xn--6qqa088eba
254+ // Prints https://xn--g6w251d
255255
256256console .log (idnURL .hostname );
257- // Prints xn--6qqa088eba
257+ // Prints xn--g6w251d
258258```
259259
260260#### url.password
@@ -929,16 +929,16 @@ any way. The `url.format(URL[, options])` method allows for basic customization
929929of the output.
930930
931931``` js
932- const myURL = new URL (' https://a:b@你好你好 ?abc#foo' );
932+ const myURL = new URL (' https://a:b@測試 ?abc#foo' );
933933
934934console .log (myURL .href );
935- // Prints https://a:b@xn--6qqa088eba /?abc#foo
935+ // Prints https://a:b@xn--g6w251d /?abc#foo
936936
937937console .log (myURL .toString ());
938- // Prints https://a:b@xn--6qqa088eba /?abc#foo
938+ // Prints https://a:b@xn--g6w251d /?abc#foo
939939
940940console .log (url .format (myURL, { fragment: false , unicode: true , auth: false }));
941- // Prints 'https://你好你好 /?abc'
941+ // Prints 'https://測試 /?abc'
942942```
943943
944944### url.pathToFileURL(path)
@@ -991,21 +991,21 @@ For example: `'#hash'`.
991991The ` host ` property is the full lower-cased host portion of the URL, including
992992the ` port ` if specified.
993993
994- For example: ` 'sub.host .com:8080' ` .
994+ For example: ` 'sub.example .com:8080' ` .
995995
996996#### urlObject.hostname
997997
998998The ` hostname ` property is the lower-cased host name portion of the ` host `
999999component * without* the ` port ` included.
10001000
1001- For example: ` 'sub.host .com' ` .
1001+ For example: ` 'sub.example .com' ` .
10021002
10031003#### urlObject.href
10041004
10051005The ` href ` property is the full URL string that was parsed with both the
10061006` protocol ` and ` host ` components converted to lower-case.
10071007
1008- For example: ` 'http://user:pass@sub.host .com:8080/p/a/t/h?query=string#hash' ` .
1008+ For example: ` 'http://user:pass@sub.example .com:8080/p/a/t/h?query=string#hash' ` .
10091009
10101010#### urlObject.path
10111011
@@ -1265,11 +1265,11 @@ using the [Punycode][] algorithm. Note, however, that a hostname *may* contain
12651265* both* Punycode encoded and percent-encoded characters:
12661266
12671267``` js
1268- const myURL = new URL (' https://%CF%80.com/foo' );
1268+ const myURL = new URL (' https://%CF%80.example. com/foo' );
12691269console .log (myURL .href );
1270- // Prints https://xn--1xa.com/foo
1270+ // Prints https://xn--1xa.example. com/foo
12711271console .log (myURL .origin );
1272- // Prints https://π.com
1272+ // Prints https://π.example. com
12731273```
12741274
12751275[ `Error` ] : errors.html#errors_class_error
0 commit comments