Browse Source

doc: fix code examples in url.md

* Update outputs.
* Refine spaces.
* Restore missing part.

PR-URL: https://github.com/nodejs/node/pull/13288
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
v6
Vse Mozhet Byt 8 years ago
parent
commit
f1b2e68d65
  1. 10
      doc/api/url.md

10
doc/api/url.md

@ -186,6 +186,7 @@ console.log(myURL.href);
// Prints https://example.org/foo // Prints https://example.org/foo
myURL.href = 'https://example.com/bar'; myURL.href = 'https://example.com/bar';
console.log(myURL.href);
// Prints https://example.com/bar // Prints https://example.com/bar
``` ```
@ -332,7 +333,7 @@ console.log(myURL.protocol);
myURL.protocol = 'ftp'; myURL.protocol = 'ftp';
console.log(myURL.href); console.log(myURL.href);
// Prints ftp://example.org // Prints ftp://example.org/
``` ```
Invalid URL protocol values assigned to the `protocol` property are ignored. Invalid URL protocol values assigned to the `protocol` property are ignored.
@ -380,7 +381,7 @@ console.log(myURL.username);
myURL.username = '123'; myURL.username = '123';
console.log(myURL.href); console.log(myURL.href);
// Prints https://123:xyz@example.com // Prints https://123:xyz@example.com/
``` ```
Any invalid URL characters appearing in the value assigned the `username` Any invalid URL characters appearing in the value assigned the `username`
@ -571,7 +572,8 @@ console.log(params.toString());
new URLSearchParams([ new URLSearchParams([
['user', 'abc', 'error'] ['user', 'abc', 'error']
]); ]);
// Throws TypeError: Each query pair must be a name/value tuple // Throws TypeError [ERR_INVALID_TUPLE]:
// Each query pair must be an iterable [name, value] tuple
``` ```
#### urlSearchParams.append(name, value) #### urlSearchParams.append(name, value)
@ -817,7 +819,7 @@ console.log(myURL.toString());
// Prints https://a:b@xn--6qqa088eba/?abc#foo // Prints https://a:b@xn--6qqa088eba/?abc#foo
console.log(url.format(myURL, { fragment: false, unicode: true, auth: false })); console.log(url.format(myURL, { fragment: false, unicode: true, auth: false }));
// Prints 'https://你好你好?abc' // Prints 'https://你好你好/?abc'
``` ```
## Legacy URL API ## Legacy URL API

Loading…
Cancel
Save