Skip to content

Commit

Permalink
refactor formatSize and added localeOption fileupload
Browse files Browse the repository at this point in the history
  • Loading branch information
SoyDiego authored and melloware committed Sep 3, 2023
1 parent 68db218 commit 98da7d3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions components/lib/fileupload/FileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,18 @@ export const FileUpload = React.memo(
};

const formatSize = (bytes) => {
const k = 1024
const dm = 3
const sizes = localeOption('fileSizeTypes')

if (bytes === 0) {
return '0 B';
}

let k = 1000,
dm = 3,
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));

return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
const i = Math.floor(Math.log(bytes) / Math.log(k));
const formattedSize = parseFloat((bytes / Math.pow(k, i)).toFixed(dm));

return `${formattedSize} ${sizes[i]}`;
};

const onFileSelect = (event) => {
Expand Down

0 comments on commit 98da7d3

Please sign in to comment.