export const getFileExtension = (fileName: string) => { if (!fileName || !fileName.includes('.')) { return ''; } return fileName.split('.').pop()?.toLowerCase(); }; export const formatBytes = (bytes: number, decimals = 2) => { if (!+bytes || bytes <= 0) { return '0 B'; } const k = 1000; const dm = decimals < 0 ? 0 : decimals; const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`; };