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

suggestion: have url.dirname() return string instead of URL #4967

Closed
iuioiua opened this issue Jun 5, 2024 · 7 comments
Closed

suggestion: have url.dirname() return string instead of URL #4967

iuioiua opened this issue Jun 5, 2024 · 7 comments
Labels
suggestion a suggestion yet to be agreed url

Comments

@iuioiua
Copy link
Contributor

iuioiua commented Jun 5, 2024

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?

@iuioiua iuioiua added suggestion a suggestion yet to be agreed url labels Jun 5, 2024
@iuioiua iuioiua changed the title suggestion: have url.basename() return string suggestion: have url.basename() return string instead of URL Jun 5, 2024
@iuioiua iuioiua mentioned this issue Jun 5, 2024
6 tasks
@marvinhagemeister
Copy link
Contributor

Doesn't it already return strings https://jsr.io/@std/url/doc/~/basename ?

@iuioiua iuioiua changed the title suggestion: have url.basename() return string instead of URL suggestion: have url.dirname() return string instead of URL Jun 5, 2024
@iuioiua
Copy link
Contributor Author

iuioiua commented Jun 5, 2024

(sighs) I meant dirname() 😅

@kt3k
Copy link
Member

kt3k commented 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

@iuioiua
Copy link
Contributor Author

iuioiua commented Jun 5, 2024

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.

@marvinhagemeister
Copy link
Contributor

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.

@iuioiua
Copy link
Contributor Author

iuioiua commented Jun 5, 2024

Alright. I'm unsure I fully agree, but let's leave it as-is.

@iuioiua iuioiua closed this as not planned Won't fix, can't repro, duplicate, stale Jun 5, 2024
@kt3k
Copy link
Member

kt3k commented Jun 6, 2024

There was also a small discussion about dirname when it was first landed #3527 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion a suggestion yet to be agreed url
Projects
None yet
Development

No branches or pull requests

3 participants