Refactor filterFileRequirements
This commit is contained in:
parent
c2c7cf18a7
commit
817f48b527
1 changed files with 10 additions and 9 deletions
|
@ -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 };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue