Skip to content

Commit

Permalink
fix(utils): simplified 'getFileExtension()' to pass all test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
damanV5 committed Feb 19, 2025
1 parent a14e493 commit 5e703b6
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/js/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ export const getAbsoluteURL = function(url) {
*/
export const getFileExtension = function(path) {
if (typeof path === 'string') {
const splitPathRe = /^(\/?)([\s\S]*?)((?:\.{1,2}|[^\/]+?)(\.*([^\.\/\?]+)))(?:[\/]*|[\?].*)$/;
const pathParts = splitPathRe.exec(path);
const cleanPath = path.split('?')[0];

if (pathParts) {
return pathParts.pop().toLowerCase();
}
}
const match = cleanPath.match(/\.([^.\/]+)$/);

return match ? match[1].toLowerCase() : '';
}
return '';
};

Expand Down

0 comments on commit 5e703b6

Please sign in to comment.