Skip to content

Commit c2d7b41

Browse files
vsemozhetbytjasnell
authored andcommitted
doc: fix code examples in url.md
* Update outputs. * Refine spaces. * Restore missing part. PR-URL: #13288 Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent cc3174a commit c2d7b41

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

doc/api/url.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ that an effort will be made to coerce the given values into strings. For
101101
instance:
102102

103103
```js
104-
const myURL = new URL({toString: () => 'https://example.org/'});
104+
const myURL = new URL({ toString: () => 'https://example.org/' });
105105
// https://example.org/
106106
```
107107

@@ -186,6 +186,7 @@ console.log(myURL.href);
186186
// Prints https://example.org/foo
187187

188188
myURL.href = 'https://example.com/bar';
189+
console.log(myURL.href);
189190
// Prints https://example.com/bar
190191
```
191192

@@ -332,7 +333,7 @@ console.log(myURL.protocol);
332333

333334
myURL.protocol = 'ftp';
334335
console.log(myURL.href);
335-
// Prints ftp://example.org
336+
// Prints ftp://example.org/
336337
```
337338

338339
Invalid URL protocol values assigned to the `protocol` property are ignored.
@@ -380,7 +381,7 @@ console.log(myURL.username);
380381

381382
myURL.username = '123';
382383
console.log(myURL.href);
383-
// Prints https://123:[email protected]
384+
// Prints https://123:[email protected]/
384385
```
385386

386387
Any invalid URL characters appearing in the value assigned the `username`
@@ -515,7 +516,7 @@ const params = new URLSearchParams({
515516
query: ['first', 'second']
516517
});
517518
console.log(params.getAll('query'));
518-
// Prints ['first,second']
519+
// Prints [ 'first,second' ]
519520
console.log(params.toString());
520521
// Prints 'user=abc&query=first%2Csecond'
521522
```
@@ -571,7 +572,8 @@ console.log(params.toString());
571572
new URLSearchParams([
572573
['user', 'abc', 'error']
573574
]);
574-
// Throws TypeError: Each query pair must be a name/value tuple
575+
// Throws TypeError [ERR_INVALID_TUPLE]:
576+
// Each query pair must be an iterable [name, value] tuple
575577
```
576578

577579
#### urlSearchParams.append(name, value)
@@ -816,8 +818,8 @@ console.log(myURL.href);
816818
console.log(myURL.toString());
817819
// Prints https://a:b@xn--6qqa088eba/?abc#foo
818820

819-
console.log(url.format(myURL, {fragment: false, unicode: true, auth: false}));
820-
// Prints 'https://你好你好?abc'
821+
console.log(url.format(myURL, { fragment: false, unicode: true, auth: false }));
822+
// Prints 'https://你好你好/?abc'
821823
```
822824

823825
## Legacy URL API

0 commit comments

Comments
 (0)