Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 272d4fa

Browse filesBrowse files
ChALkeRMylesBorins
authored andcommitted
doc: use reserved domains for examples in url.md
Changes non-reserved domains to reserved ones in url.md. PR-URL: #23359 Refs: https://www.iana.org/domains/reserved Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 43d4977 commit 272d4fa
Copy full SHA for 272d4fa

File tree

Expand file treeCollapse file tree

1 file changed

+48
-48
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+48
-48
lines changed
Open diff view settings
Collapse file

‎doc/api/url.md‎

Copy file name to clipboardExpand all lines: doc/api/url.md
+48-48Lines changed: 48 additions & 48 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -26,47 +26,47 @@ backwards compatibility with existing applications. New application code
2626
should use the WHATWG API.
2727

2828
A 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
3131
properties of a WHATWG `URL` object.
3232

3333
WHATWG 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

5757
Parsing the URL string using the WHATWG API:
5858

5959
```js
6060
const 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

6464
Parsing the URL string using the Legacy API:
6565

6666
```js
6767
const url = require('url');
6868
const 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
120120
automatically 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

127127
This 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
132132
the `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://測試');
253253
console.log(idnURL.origin);
254-
// Prints https://xn--6qqa088eba
254+
// Prints https://xn--g6w251d
255255

256256
console.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
929929
of 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

934934
console.log(myURL.href);
935-
// Prints https://a:b@xn--6qqa088eba/?abc#foo
935+
// Prints https://a:b@xn--g6w251d/?abc#foo
936936

937937
console.log(myURL.toString());
938-
// Prints https://a:b@xn--6qqa088eba/?abc#foo
938+
// Prints https://a:b@xn--g6w251d/?abc#foo
939939

940940
console.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'`.
991991
The `host` property is the full lower-cased host portion of the URL, including
992992
the `port` if specified.
993993

994-
For example: `'sub.host.com:8080'`.
994+
For example: `'sub.example.com:8080'`.
995995

996996
#### urlObject.hostname
997997

998998
The `hostname` property is the lower-cased host name portion of the `host`
999999
component *without* the `port` included.
10001000

1001-
For example: `'sub.host.com'`.
1001+
For example: `'sub.example.com'`.
10021002

10031003
#### urlObject.href
10041004

10051005
The `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');
12691269
console.log(myURL.href);
1270-
// Prints https://xn--1xa.com/foo
1270+
// Prints https://xn--1xa.example.com/foo
12711271
console.log(myURL.origin);
1272-
// Prints https://π.com
1272+
// Prints https://π.example.com
12731273
```
12741274

12751275
[`Error`]: errors.html#errors_class_error

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.