Uh oh!
There was an error while loading. Please reload this page.
doc: improve WHATWG url constructor code example - #32782
Conversation
## Why this PR ? Currently, the URL docs for the WHATWG URL spec support are somewhat lacking in their code example of how to access the new URL constructor that lives inside the core url package. ## Suggested change Improve the code example that shows how the new URL constructor should be accessed to begin with.
lirantal
commented
Apr 11, 2020
If we want to promote accessing the new WHATWG URL from the global scope then maybe the code example as-is is ok, but otherwise, since this is a docs for the core URL module then it is somewhat confusing how to access since doing this won't work: constURL=require('url')constmyURL=newURL('..') |
addaleax
commented
Apr 11, 2020
@lirantal Yeah, since all supported Node.js versions have URL on the global object, I’d not document Maybe the |
lirantal
commented
Apr 11, 2020
Exactly, so it depends what we want to promote :-) |
addaleax
commented
Apr 14, 2020
@lirantal Since nobody else has weighed in here yet: I’d say let’s not do this, and instead mention this as an alternative possibility for access in the URL constructor’s documentation section. |
lirantal
commented
Apr 14, 2020
Sure. So would we replace this one https://github.com/nodejs/node/pull/32782/files#diff-dd182d238def46a3af0d112f617e8838L104 with the option I suggested or just add it as a note below it? I need an actual code example would be good. |
| Parsing the URL string using the WHATWG API: | ||
| ```js | ||
| const URL = require('url').URL |
There was a problem hiding this comment.
Now that URL is global, this is not strictly required. This might be improved by explaining that distinction?
There was a problem hiding this comment.
I know it works global :)
I'm thinking out loud in this PR whether we want to promote that or not and yes to make one or the other more explicit so devs are aware.
addaleax
commented
Apr 15, 2020
@lirantal I think an explicit second example would be good. E.g.:
|
lirantal
commented
Apr 20, 2020
@addaleax added it to the constructor example instead of the generic one on the intro. |
addaleax
left a comment
There was a problem hiding this comment.
LGTM with the linter failure fixed (should be ```js)
lirantal
commented
Apr 25, 2020
all fixed up 👍 |
lirantal
commented
Apr 25, 2020
CI fails on |
Currently, the URL docs for the WHATWG URL spec support are somewhat lacking in their code example of how to access the new URL constructor that lives inside the core url package. PR-URL: #32782 Reviewed-By: Anna Henningsen <anna@addaleax.net>
addaleax
commented
Apr 27, 2020
Landed in 6b2e3af |
lirantal
commented
Apr 28, 2020
Thanks Anna 👍 |
Currently, the URL docs for the WHATWG URL spec support are somewhat lacking in their code example of how to access the new URL constructor that lives inside the core url package. PR-URL: #32782 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Currently, the URL docs for the WHATWG URL spec support are somewhat lacking in their code example of how to access the new URL constructor that lives inside the core url package. PR-URL: #32782 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Currently, the URL docs for the WHATWG URL spec support are somewhat lacking in their code example of how to access the new URL constructor that lives inside the core url package. PR-URL: #32782 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Currently, the URL docs for the WHATWG URL spec support are somewhat lacking in their code example of how to access the new URL constructor that lives inside the core url package. PR-URL: #32782 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Currently, the URL docs for the WHATWG URL spec support are somewhat lacking in their code example of how to access the new URL constructor that lives inside the core url package. PR-URL: #32782 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Currently, the URL docs for the WHATWG URL spec support are somewhat lacking in their code example of how to access the new URL constructor that lives inside the core url package. PR-URL: #32782 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Why this PR ?
Currently, the URL docs for the WHATWG URL spec support are
somewhat lacking in their code example of how to access the
new URL constructor that lives inside the core url package.
Suggested change
Improve the code example that shows how the new URL
constructor should be accessed to begin with.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes