/
t3
/
web-ui
Обзор
Документация
Войти
/
t3
/
web-ui
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
src/lib/utils.ts
36 строк
1 KB
Ivan Shibkikh
init
22 июл 2026, 22:03
22 июл 2026, 22:03
c56855a
Код
Авторство
О чём код?
import { type ClassValue, clsx } from "clsx"; import { twMerge } from "tailwind-merge"; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } export function formatBytes(bytes: number): string { if (bytes === 0) return "0 Б"; const units = ["Б", "КБ", "МБ", "ГБ", "ТБ"]; const i = Math.floor(Math.log(bytes) / Math.log(1024)); return `${(bytes / Math.pow(1024, i)).toFixed(i > 0 ? 1 : 0)} ${units[i]}`; } export function formatDate(dateStr: string | null | undefined): string { if (!dateStr) return "—"; try { return new Intl.DateTimeFormat("ru-RU", { dateStyle: "medium", timeStyle: "short", }).format(new Date(dateStr)); } catch { return dateStr; } } export function formatDateShort(dateStr: string | null | undefined): string { if (!dateStr) return "—"; try { return new Intl.DateTimeFormat("ru-RU", { dateStyle: "short", }).format(new Date(dateStr)); } catch { return dateStr; } }