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
suggestion: have url.dirname() return string instead of URL #4967
It currently returns a URL instead of a string. I find this behavior surprising, as it requires the user to call .href in most cases. Do you have any thoughts, @marvinhagemeister?
changed the title [-]suggestion: have `url.basename()` return `string`[/-][+]suggestion: have `url.basename()` return `string` instead of `URL`[/+]on Jun 5, 2024
changed the title [-]suggestion: have `url.basename()` return `string` instead of `URL`[/-][+]suggestion: have `url.dirname()` return `string` instead of `URL`[/+]on Jun 5, 2024
APIs in url consistently return URL instance when the returned value can be expressed as URL (dirname, join, normalize). extname and basename return string as the returned values can't be expressed as URLs
It makes sense for join() (join URLs) and normalize() (normalize a URL) to return URLs. I'd expect dirname() to behave the same way basename() and extname(), as their names imply.
Both points of views make sense to me and are valid options. So it comes more down to what we expect developers to use it for. I'm trying to make a case from that perspective. In apps I've written the dirname() function on paths is typically used to traverse upwards, like finding the nearest deno.json for example. A similar use case seems to apply to URLs as well. If the type changes to a string you'd constantly have to cast it back to a URL again. For that reason it seems to make more sense to me that dirname() returns a URL instance. You can always get back the stringified variant by doing url.pathname I guess.
Activity
[-]suggestion: have `url.basename()` return `string`[/-][+]suggestion: have `url.basename()` return `string` instead of `URL`[/+]marvinhagemeister commentedon Jun 5, 2024
Doesn't it already return strings https://jsr.io/@std/url/doc/~/basename ?
[-]suggestion: have `url.basename()` return `string` instead of `URL`[/-][+]suggestion: have `url.dirname()` return `string` instead of `URL`[/+]iuioiua commentedon Jun 5, 2024
(sighs) I meant
dirname()😅kt3k commentedon Jun 5, 2024
APIs in
urlconsistently return URL instance when the returned value can be expressed as URL (dirname,join,normalize).extnameandbasenamereturn string as the returned values can't be expressed as URLsiuioiua commentedon Jun 5, 2024
It makes sense for
join()(join URLs) andnormalize()(normalize a URL) to returnURLs. I'd expectdirname()to behave the same waybasename()andextname(), as their names imply.marvinhagemeister commentedon Jun 5, 2024
Both points of views make sense to me and are valid options. So it comes more down to what we expect developers to use it for. I'm trying to make a case from that perspective. In apps I've written the
dirname()function on paths is typically used to traverse upwards, like finding the nearestdeno.jsonfor example. A similar use case seems to apply to URLs as well. If the type changes to astringyou'd constantly have to cast it back to aURLagain. For that reason it seems to make more sense to me thatdirname()returns aURLinstance. You can always get back the stringified variant by doingurl.pathnameI guess.iuioiua commentedon Jun 5, 2024
Alright. I'm unsure I fully agree, but let's leave it as-is.
kt3k commentedon Jun 6, 2024
There was also a small discussion about
dirnamewhen it was first landed #3527 (comment)