export const formatBytes = (bytes: number | undefined, decimals = 2, isBinary = true) => { if (!bytes) { return '0 Bytes'; } const k = isBinary ? 1024 : 1000; const dm = Math.max(0, decimals); const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`; }; export const getImageSize = (url: string) => { return new Promise<{ width: number; height: number }>((resolve, reject) => { const image = document.createElement('img'); image.onload = () => { resolve({ width: image.width, height: image.height }); }; image.onerror = () => { reject(undefined); }; image.src = url; }); }; export const convertDomainName = (value: string) => value.toLowerCase().replace(/ /g, '');