From f5958586b7b7e3e53e2d3d085987b7e451f72362 Mon Sep 17 00:00:00 2001 From: Anthony GAEREMYNCK <1@anthony.sh> Date: Fri, 31 Jul 2026 15:53:03 +0200 Subject: [PATCH] feat(frontend): add formatBytes util for human-readable file sizes Co-Authored-By: Claude Sonnet 5 --- frontend/src/utils/formatBytes.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 frontend/src/utils/formatBytes.js 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]}`; +}