UNPKG

@i-novus/ui-core

Version:

Базовые UI компоненты

30 lines (29 loc) 897 B
export const formatFileSize = (bytes) => { const binaryThousand = 1024; const sizes = ['Байт', 'Кб', 'Мб', 'Гб']; const i = Math.floor(Math.log(bytes) / Math.log(binaryThousand)); if (bytes === 0) { return 0; } return `${Math.round((bytes / binaryThousand ** i) * 10) / 10} ${sizes[i]}`; }; export const isSameOrigin = (url1, url2) => { try { const firstUrl = new URL(url1); const secondUrl = new URL(url2); return firstUrl.origin === secondUrl.origin; // eslint-disable-next-line @typescript-eslint/no-unused-vars } catch (e) { return false; } }; export const isUploadError = (file) => { return file.error !== undefined; }; export const isUploadSuccess = (file) => { return file.url !== undefined; }; export const isUploadInProgress = (file) => { return file.progress !== undefined; };