Skip to content

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

Closed as not planned

Description

@iuioiua

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?

Activity

  1. added
    suggestion
    on Jun 5, 2024
  2. changed the title [-]suggestion: have `url.basename()` return `string`[/-] [+]suggestion: have `url.basename()` return `string` instead of `URL`[/+] on Jun 5, 2024
  3. marvinhagemeister commented on Jun 5, 2024

    @marvinhagemeister
    Contributor
  4. 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
  5. iuioiua commented on Jun 5, 2024

    @iuioiua
    ContributorAuthor

    (sighs) I meant dirname() 😅

  6. kt3k commented on Jun 5, 2024

    @kt3k
    Contributor

    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

  7. iuioiua commented on Jun 5, 2024

    @iuioiua
    ContributorAuthor

    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.

  8. marvinhagemeister commented on Jun 5, 2024

    @marvinhagemeister
    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.

  9. iuioiua commented on Jun 5, 2024

    @iuioiua
    ContributorAuthor

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

  10. kt3k commented on Jun 6, 2024

    @kt3k
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    suggestionurl

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions