Refactor filterFileRequirements

This commit is contained in:
Leonardo Murça 2022-11-18 15:48:00 -03:00
parent c2c7cf18a7
commit 817f48b527

View file

@ -1,20 +1,21 @@
const formattedFilenameExt = (name) =>
`.${name.split(".").pop().toLowerCase()}`;
const areRequirementsFulfilled = (requirements, file) =>
requirements.maxSize >= file.size &&
requirements.supportedFormats.includes(formattedFilenameExt(file.name));
export function filterFileRequirements(files, requirements) { export function filterFileRequirements(files, requirements) {
let accepted = []; let accepted = [];
let rejected = []; let rejected = [];
for (var i = 0, file; (file = files[i]); i++) { Array.from(files).forEach((file) => {
if (file) { if (file) {
if ( if (areRequirementsFulfilled(requirements, file)) {
requirements.maxSize >= file.size &&
requirements.supportedFormats.includes(
`.${file.name.split(".").pop().toLowerCase()}`
)
) {
accepted.push(file); accepted.push(file);
} else { } else {
rejected.push(file); rejected.push(file);
} }
} }
} });
return { accepted, rejected }; return { accepted, rejected };
} }