-
Notifications
You must be signed in to change notification settings - Fork 0
Fixed file extension extraction issue for filenames with multiple dots. #62
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think line 16 should have a semicolon appended at the end (;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this modification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be slightly better if rewritten so that there is only one return statement, with the conditional statement setting the values.
export function getFileNameAndFileType(filename: string): { fileName: string; fileType: string } {
const lastDotIndex = filename.lastIndexOf(".");
const fileName = (lastDotIndex === -1) ? filename : filename.substring(0, lastDotIndex); // Extract name before last dot
const fileType = (lastDotIndex === -1) ? "" : filename.substring(lastDotIndex + 1); // Extract extension after last dot
return { fileName, fileType };
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did the following modifications.
- Improved error handling compared to the previous behavior where invalid filenames would silently return an empty file type.
- Now throws errors for missing or invalid file extensions (e.g., no
.
or filename ends with a.
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve this, but can you please make and test the small changes I request?
Refactored File Extension Extraction
.yml
or.json
) and slicing based on fixed lengths, the new solution useslastIndexOf('.')
to reliably separate the filename and extension.Backend Refactor