diff --git a/frontend/src/utils/formatBytes.js b/frontend/src/utils/formatBytes.js new file mode 100644 index 0000000..aab18e6 --- /dev/null +++ b/frontend/src/utils/formatBytes.js @@ -0,0 +1,10 @@ +const UNITS = ['B', 'KB', 'MB', 'GB']; + +export function formatBytes(bytes) { + if (!bytes || bytes <= 0) return '0 B'; + const exponent = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), UNITS.length - 1); + const value = bytes / 1024 ** exponent; + const rounded = Math.round(value * 10) / 10; + const formatted = Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(1); + return `${formatted} ${UNITS[exponent]}`; +}