/
dmitriysturov
/
workspaces_platform
Обзор
Документация
Войти
/
dmitriysturov
/
workspaces_platform
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
frontend/src/utils/format.ts
66 строк
2 KB
dmitriysturov
vkr
04 июн 2026, 22:24
04 июн 2026, 22:24
971dfdc
Код
Авторство
О чём код?
export function formatDate(value: string) { return new Intl.DateTimeFormat('ru-RU', { day: '2-digit', month: 'short', year: 'numeric', }).format(new Date(value)) } export function formatDateTime(value: string) { return new Intl.DateTimeFormat('ru-RU', { day: '2-digit', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit', }).format(new Date(value)) } export function formatFileSize(bytes: number) { if (bytes < 1024) { return `${bytes} B` } const units = ['KB', 'MB', 'GB'] as const let value = bytes / 1024 let unitIndex = 0 while (value >= 1024 && unitIndex < units.length - 1) { value /= 1024 unitIndex += 1 } return `${value.toFixed(value >= 10 ? 0 : 1)} ${units[unitIndex]}` } export type DisplayUser = { id?: string | null name?: string | null lastName?: string | null email?: string | null } export function userDisplayName(user: DisplayUser | null | undefined, fallback = 'Пользователь') { if (!user) { return fallback } const parts = [user.name, user.lastName].map((part) => part?.trim()).filter(Boolean) return parts.length > 0 ? parts.join(' ') : user.email || user.id || fallback } export function friendlyError(error: unknown, fallback: string) { if (error instanceof Error && error.message) { if (error.message.includes('Workspace cannot be deleted')) { return 'Нельзя удалить пространство, пока внутри него есть проекты.' } if (error.message.includes('Unauthorized') || error.message.includes('Authorization')) { return 'Сессия истекла. Войдите снова.' } return error.message } return fallback }