Files
bodyshop/client/src/utils/formatbytes.js
Dave Richer e83badb454 - the great reformat
Signed-off-by: Dave Richer <dave@imexsystems.ca>
2024-02-06 18:20:58 -05:00

11 lines
334 B
JavaScript

export default function formatBytes(a, b = 2) {
if (0 === a || !a) return "0 Bytes";
const c = 0 > b ? 0 : b,
d = Math.floor(Math.log(a) / Math.log(1024));
return (
parseFloat((a / Math.pow(1024, d)).toFixed(c)) +
" " +
["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"][d]
);
}