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

feat(path/unstable): support URL in extname() #5818

Merged
merged 5 commits into from
Aug 26, 2024
Merged

feat(path/unstable): support URL in extname() #5818

merged 5 commits into from
Aug 26, 2024

Conversation

iuioiua
Copy link
Contributor

@iuioiua iuioiua commented Aug 26, 2024

Towards #5537

@iuioiua iuioiua requested a review from kt3k as a code owner August 26, 2024 02:42
@iuioiua iuioiua enabled auto-merge (squash) August 26, 2024 02:42
@github-actions github-actions bot added the path label Aug 26, 2024
Copy link

codecov bot commented Aug 26, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Project coverage is 96.25%. Comparing base (0019ac7) to head (8452f04).
Report is 11 commits behind head on main.

Files Patch % Lines
path/extname.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5818   +/-   ##
=======================================
  Coverage   96.25%   96.25%           
=======================================
  Files         479      479           
  Lines       38697    38748   +51     
  Branches     5613     5621    +8     
=======================================
+ Hits        37246    37298   +52     
+ Misses       1409     1408    -1     
  Partials       42       42           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@iuioiua iuioiua changed the title feat(path/unstable): support URL in extname() feat(path/unstable): support URL in extname() Aug 26, 2024
export function extname(path: URL): string;
export function extname(path: string | URL): string {
if (path instanceof URL) {
path = path.pathname;
Copy link
Member

Choose a reason for hiding this comment

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

Can you use fromFileUrl instead? This allows other random urls such as http:, data:, jsr:, node:, etc, which is not aligned to how dirname works with those url types.

Copy link
Contributor Author

@iuioiua iuioiua Aug 26, 2024

Choose a reason for hiding this comment

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

What's the harm in allowing these other URL schemes?

Copy link
Member

Choose a reason for hiding this comment

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

In data: scheme, the pathname doesn't represent the path, but it represent arbitrary data. The return value of extname can be any random value in that case.

*/
export function extname(path: URL): string;
export function extname(path: string | URL): string {
// deno-lint-ignore no-explicit-any
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't any be avoided with toString() or String(path)?

Copy link
Member

Choose a reason for hiding this comment

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

We like to do path instanceof URL check in each implementation. String(path) makes that check not working.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM

@iuioiua iuioiua merged commit 3666d84 into main Aug 26, 2024
16 checks passed
@iuioiua iuioiua deleted the path-extname branch August 26, 2024 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants