Skip to content

feat(std): Add std/url module. - #3527

Merged
kt3k merged 7 commits into
denoland:mainfrom
tr1ckydev:main
Sep 1, 2023
Merged

kt3k merged 7 commits into
denoland:mainfrom
tr1ckydev:main

Conversation

@tr1ckydev

@tr1ckydev tr1ckydev commented Aug 8, 2023 •

Copy link
Copy Markdown
Contributor

Utilities for working with URL paths (#3515).

closes #3515

Utilities for working with URL paths.
@CLAassistant

CLAassistant commented Aug 8, 2023 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread url/dirname_test.ts Resolved
Comment thread url/extname_test.ts Resolved
Comment thread url/join_test.ts
Comment on lines +3 to +26
import { assertEquals } from "../assert/mod.ts";
import * as url from "./mod.ts";

const TESTSUITE: [[string | URL, ...string[]], URL][] = [
[
["https://deno.land", "std", "assert", "mod.ts"],
new URL("https://deno.land/std/assert/mod.ts"),
],
[
[new URL("https://deno.land"), "std", "assert", "mod.ts"],
new URL("https://deno.land/std/assert/mod.ts"),
],
[
[new URL("https://deno.land//"), "/std/", "/assert/", "//mod.ts"],
new URL("https://deno.land/std/assert/mod.ts"),
],
[["https://deno.land/"], new URL("https://deno.land/")],
];

Deno.test("join", function () {
for (const [[test_url, ...paths], expected] of TESTSUITE) {
assertEquals(url.join(test_url, ...paths), expected);
}
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I'm looking at the tests, I'm not sure if join even makes sense.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it so?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it handles edgecases around double / so maybe it's still useful. Not entirely sure what the utility is. Thoughts @marvinhagemeister?

Comment thread url/normalize.ts Resolved
@tr1ckydev

Copy link
Copy Markdown
Contributor Author

Should common from std/path be implemented for url? Need suggestion.

@lino-levan

Copy link
Copy Markdown
Contributor

I'm trying to think of a usecase and can't come up with one off of the top of my head. I think a lot of these things can be done as a follow-up PR. So no pressure to get everything in right now!

@tr1ckydev

Copy link
Copy Markdown
Contributor Author

I have fixed couple of bugs and added new edge cases tests. Will be adding them later by today.

@timreichen

Copy link
Copy Markdown
Contributor

What would you think of adding a isUrl(input: string) function, either in this PR or the future?
Seems like both isurl and is-url have millions of weekly downloads.

@0f-0b

0f-0b commented Aug 9, 2023

Copy link
Copy Markdown
Contributor

What would you think of adding a isUrl(input: string) function, either in this PR or the future?

There is URL.canParse, although browser support is currently poor.

@tr1ckydev

Copy link
Copy Markdown
Contributor Author

https://github.com/tr1ckydev/pathurl
This is my package with all the proposed path functions for URLs along with various tests. If it's acceptable then I will port all the functions from here into std/url.

Comment thread url/normalize.ts Resolved
@kt3k

kt3k commented Sep 1, 2023

Copy link
Copy Markdown
Contributor

dirname might sound strange because it returns a URL instead of a string (it doesn't feel like 'name' to me), but this looks good enough for first pass.

@kt3k kt3k left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tr1ckydev LGTM. Nice work!

@kt3k
kt3k merged commit 4e44fa7 into denoland:main Sep 1, 2023
@tr1ckydev

Copy link
Copy Markdown
Contributor Author

dirname might sound strange because it returns a URL instead of a string (it doesn't feel like 'name' to me), but this looks good enough for first pass.

Agree, but as it's from url module so it can be expected. Even though dirname from path module returns parent path so works in case of url too imo.

@tr1ckydev

Copy link
Copy Markdown
Contributor Author

@tr1ckydev LGTM. Nice work!

Thank you. I have also send another pull request which bug fixes many functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add std/url with URL utilities

6 participants