feat(frontend): add formatBytes util for human-readable file sizes
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -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]}`;
|
||||
}
|
||||
Reference in New Issue
Block a user