1const formatFileSize = (bytes: number): string => {
2 if (bytes === 0) return "0 B";
3 const k = 1024;
4 const sizes = ["B", "KB", "MB", "GB"];
5 const i = Math.floor(Math.log(bytes) / Math.log(k));
6 return `${(bytes / Math.pow(k, i)).toFixed(i === 0 ? 0 : 1)} ${sizes[i]}`;
7};
8
9export { formatFileSize };