Files
lemma/app/src/utils/formatBytes.js
2024-11-12 21:25:02 +01:00

11 lines
272 B
JavaScript

export const formatBytes = (bytes) => {
const units = ['B', 'KB', 'MB', 'GB'];
let size = bytes;
let unitIndex = 0;
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024;
unitIndex++;
}
return `${size.toFixed(1)} ${units[unitIndex]}`;
};