Skip to content

Commit

Permalink
Case insensitive check for file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
tomodwyer committed Oct 24, 2023
1 parent 8fee986 commit 987ba06
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions assets/src/scripts/_file-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ async function fileLoader(ext, url) {

if (canDisplay(ext)) {
if (isCsv(ext) || isTxt(ext)) {
res = await response.text();
return response.text();
}

if (isJson(ext)) {
res = await response.json();
return response.json();
}
}

Expand Down
6 changes: 4 additions & 2 deletions assets/src/scripts/_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ export const isCsv = (ext) => ext.toLowerCase() === "csv";
export const isImg = (ext) =>
["gif", "jpg", "jpeg", "png", "svg"].includes(ext.toLowerCase());

export const TEXT_TYPES = ["txt", "md", "py", "yaml", "R", "log"];
export const TEXT_TYPES = ["txt", "md", "py", "yaml", "r", "log"];
/**
* Confirm if file is .txt
* @param {string} ext - file extension
* @returns {boolean}
*/
export function isTxt(ext) {
return TEXT_TYPES.includes(ext.toLowerCase());
return TEXT_TYPES.some((type) =>
type.toLowerCase().localeCompare(ext.toLowerCase())
);
}

/**
Expand Down

0 comments on commit 987ba06

Please sign in to comment.