Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: fix code examples in url.md #13288

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions doc/api/url.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ that an effort will be made to coerce the given values into strings. For
instance:

```js
const myURL = new URL({toString: () => 'https://example.org/'});
const myURL = new URL({ toString: () => 'https://example.org/' });
// https://example.org/
```

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

myURL.href = 'https://example.com/bar';
console.log(myURL.href);
// Prints https://example.com/bar
```

Expand Down Expand Up @@ -332,7 +333,7 @@ console.log(myURL.protocol);

myURL.protocol = 'ftp';
console.log(myURL.href);
// Prints ftp://example.org
// Prints ftp://example.org/
```

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

myURL.username = '123';
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`
Expand Down Expand Up @@ -515,7 +516,7 @@ const params = new URLSearchParams({
query: ['first', 'second']
});
console.log(params.getAll('query'));
// Prints ['first,second']
// Prints [ 'first,second' ]
Copy link
Contributor

@refack refack May 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ 'first', 'second' ] space after the comma

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an array with a single element :) It literally prints [ 'first,second' ].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. I was trying console.log(['first','second'])

console.log(params.toString());
// Prints 'user=abc&query=first%2Csecond'
```
Expand Down Expand Up @@ -571,7 +572,8 @@ console.log(params.toString());
new URLSearchParams([
['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)
Expand Down Expand Up @@ -816,8 +818,8 @@ console.log(myURL.href);
console.log(myURL.toString());
// Prints https://a:b@xn--6qqa088eba/?abc#foo

console.log(url.format(myURL, {fragment: false, unicode: true, auth: false}));
// Prints 'https://你好你好?abc'
console.log(url.format(myURL, { fragment: false, unicode: true, auth: false }));
// Prints 'https://你好你好/?abc'
```

## Legacy URL API
Expand Down