You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WhatWG URL provides no suitable replacement for url.format() #25099
fwiw, URL purposely doesn't expose ways to create relative urls, so there isn't really any way to represent the example you posted with a URL. i'd be interested in a version of the api which builds absolute urls though.
Yeah, this really isn't that big of an issue. It's trivial to wrap the non-eronomic bits into a utility function that is easier to use. Alternatively, we could go ask the WHATWG for a new function.
The idea that there is no alternative in this case is incorrect. There is an alternative, it's just not as simple to use out of the box (although, it's relatively trivial to build a utility wrapper around that can sit out in userland) and some folks are unhappy with the alternative. Also, it would be relatively straightforward to submit a proposal to add a URL.format() utility function to the standard if someone wished to do so.
Also, keep in mind that the deprecation of url.format() is docs only and is expected to remain docs-only for quite some time.
The idea that there is no alternative in this case is incorrect. There is an alternative, it's just not as simple to use out of the box
I should have clarified. I'm meant no core API alternatives. I see this happen in Node when deprecating/removing chunks of functionality. Occasionally useful APIs get caught up in the cleanup. Is there a way to better prevent this kind of thing in the future?
I should have clarified. I'm meant no core API alternatives. I see this happen in Node when deprecating/removing chunks of functionality. Occasionally useful APIs get caught up in the cleanup. Is there a way to better prevent this kind of thing in the future?
I don't think so, being useful always depends on the implementation or requirement.
The following suggestion would be big effort, might not be possible, but if we're brainstorming and it's all about idea quantity and not (yet) about quality, here it is: Get CITGM to the point where it's green on master. Run it nightly. Back out changes that break things and fix the issue in the ecosystem, then re-land on master.
However, that will only impact runtime deprecations and breaking changes. Issues with doc-only deprecations obviously wouldn't be caught by that. But is that really that much of a problem? Undoing a doc-only deprecation is pretty simple (minus the politics, which I guess is kinda the point).
Examples showing how to use the WHAT-WG URL parser to build a URL from components and how to get the serialized URL string have been added to the documentation.
We can't attach a new static member to the URL class itself unless it's added to the spec. But adding something like this to the url module would be ok.
Activity
devsnek commentedon Dec 18, 2018
fwiw, URL purposely doesn't expose ways to create relative urls, so there isn't really any way to represent the example you posted with a URL. i'd be interested in a version of the api which builds absolute urls though.
mcollina commentedon Dec 18, 2018
Tagging tsc-agenda @nodejs/tsc
targos commentedon Dec 18, 2018
It seems premature to me to have the discussion brought up to the TSC before it happened here.
jasnell commentedon Dec 18, 2018
Yeah, this really isn't that big of an issue. It's trivial to wrap the non-eronomic bits into a utility function that is easier to use. Alternatively, we could go ask the WHATWG for a new function.
watilde commentedon Dec 18, 2018
Related discussion to relative URL in WHATWG: whatwg/url#421
jdalton commentedon Dec 20, 2018
I'm also not a fan of deprecating useful APIs with no alternatives. Is there a way to better prevent this kind of thing in the future?
jasnell commentedon Dec 20, 2018
The idea that there is no alternative in this case is incorrect. There is an alternative, it's just not as simple to use out of the box (although, it's relatively trivial to build a utility wrapper around that can sit out in userland) and some folks are unhappy with the alternative. Also, it would be relatively straightforward to submit a proposal to add a
URL.format()utility function to the standard if someone wished to do so.Also, keep in mind that the deprecation of
url.format()is docs only and is expected to remain docs-only for quite some time.jdalton commentedon Dec 20, 2018
I should have clarified. I'm meant no core API alternatives. I see this happen in Node when deprecating/removing chunks of functionality. Occasionally useful APIs get caught up in the cleanup. Is there a way to better prevent this kind of thing in the future?
juanarbol commentedon Dec 29, 2018
I don't think so, being useful always depends on the implementation or requirement.
jdalton commentedon Dec 29, 2018
Some ideas.
Trott commentedon Dec 29, 2018
The following suggestion would be big effort, might not be possible, but if we're brainstorming and it's all about idea quantity and not (yet) about quality, here it is: Get CITGM to the point where it's green on master. Run it nightly. Back out changes that break things and fix the issue in the ecosystem, then re-land on master.
However, that will only impact runtime deprecations and breaking changes. Issues with doc-only deprecations obviously wouldn't be caught by that. But is that really that much of a problem? Undoing a doc-only deprecation is pretty simple (minus the politics, which I guess is kinda the point).
26 remaining items
Fishrock123 commentedon Mar 19, 2021
This is not concerned with the exact semantics of
url.format()but rather the general things it is used for.bmeck commentedon Mar 19, 2021
@Fishrock123 is the expectation of general usage that it always outputs a valid URL (including the protocol)?
Fishrock123 commentedon Mar 19, 2021
Ok I'll tease the issue apart more, there are two issues:
URLobject from parts is not straightforward.URLobject is non-obvious. This is probably just documentation if anything. Maybe it's better than in 2018.jasnell commentedon Mar 19, 2021
Alternatively...
Is this just a documentation issue then?
jasnell commentedon Mar 22, 2021
Examples showing how to use the WHAT-WG URL parser to build a URL from components and how to get the serialized URL string have been added to the documentation.
doc: revoke deprecation of legacy url, change status to legacy
doc: revoke deprecation of legacy url, change status to legacy
Fishrock123 commentedon May 25, 2021
If this is documented appropriately and if the old url api is no longer deprecated, feel free to close this.
jfoclpf commentedon Dec 12, 2021
A fully adaptable one-liner replacer for
url.format(urlObject)would beTest it here
jasnell commentedon Dec 12, 2021
We can't attach a new static member to the URL class itself unless it's added to the spec. But adding something like this to the url module would be ok.
jfoclpf commentedon Dec 13, 2021
@jasnell it makes perfect sense, yes, please do kindly add a method to the node url module
clhuang commentedon Sep 16, 2022
another thing I'd like to point out is that
url.formathandles ipv6 hosts correctly, whereas none of the other alternatives do:doc: revoke deprecation of legacy url, change status to legacy