-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: add URL.format() example #18888
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -948,6 +948,24 @@ changes: | |
The `url.format()` method returns a formatted URL string derived from | ||
`urlObject`. | ||
|
||
Example: | ||
|
||
```js | ||
const URL = require('url'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although it appears in other examples in this doc, I think in general we tend to leave out the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! But we do use |
||
|
||
URL.format({ | ||
protocol: 'https', | ||
hostname: `example.com`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the backticks intended? If so, are not they a bit confusing here? With them, a template literal/a tag function/other quotes inside are usually expected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, @vsemozhetbyt. Backticks were not intentional there. Fixed. |
||
pathname: '/some/path', | ||
query: { | ||
page: 1, | ||
format: 'json' | ||
} | ||
}); | ||
|
||
// => 'https://example.com/some/path?page=1&format=json' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other places in the file use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did a search in the docs and found several instances of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be open to just doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case I only spoke about this specific document. And yes, So I personally would say using |
||
``` | ||
|
||
If `urlObject` is not an object or a string, `url.format()` will throw a | ||
[`TypeError`][]. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: You can remove
Example:
too. It's obvious that it is an example.