Spaces:
Paused
Paused
Download apps/web/src/lib/utils.ts from mohammed978/teteffd: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/spaces/mohammed978/teteffd/resolve/main/apps/web/src/lib/utils.ts
- Command line
-
hf download hf://spaces/mohammed978/teteffd/apps/web/src/lib/utils.ts
-
curl -L -o utils.ts https://huggingface.co/spaces/mohammed978/teteffd/resolve/main/apps/web/src/lib/utils.ts
1.75 kB
| import { clsx, type ClassValue } from 'clsx' | |
| import { twMerge } from 'tailwind-merge' | |
| import type { Role } from './types' | |
| export function cn(...inputs: ClassValue[]) { | |
| return twMerge(clsx(inputs)) | |
| } | |
| export function formatDate(input: Date | string | number, opts?: Intl.DateTimeFormatOptions) { | |
| const d = typeof input === 'string' || typeof input === 'number' ? new Date(input) : input | |
| return new Intl.DateTimeFormat('en', { | |
| month: 'short', | |
| day: 'numeric', | |
| hour: '2-digit', | |
| minute: '2-digit', | |
| ...opts, | |
| }).format(d) | |
| } | |
| export function formatRelative(input: Date | string | number) { | |
| const d = typeof input === 'string' || typeof input === 'number' ? new Date(input) : input | |
| const diff = (Date.now() - d.getTime()) / 1000 | |
| if (diff < 60) return 'just now' | |
| if (diff < 3600) return `${Math.floor(diff / 60)}m ago` | |
| if (diff < 86400) return `${Math.floor(diff / 3600)}h ago` | |
| if (diff < 86400 * 7) return `${Math.floor(diff / 86400)}d ago` | |
| return formatDate(d, { month: 'short', day: 'numeric' }) | |
| } | |
| export function formatNumber(n: number) { | |
| if (n < 1000) return n.toString() | |
| if (n < 1_000_000) return `${(n / 1000).toFixed(1)}k` | |
| return `${(n / 1_000_000).toFixed(1)}M` | |
| } | |
| export function bytes(n: number) { | |
| if (n < 1024) return `${n} B` | |
| if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB` | |
| return `${(n / 1024 / 1024).toFixed(1)} MB` | |
| } | |
| export function safeJSON<T>(text: string, fallback: T): T { | |
| try { return JSON.parse(text) } catch { return fallback } | |
| } | |
| export function isDeveloper(role?: Role): boolean { | |
| return !!role && ['developer', 'admin', 'superadmin'].includes(role) | |
| } | |
| export function isAdmin(role?: Role): boolean { | |
| return !!role && ['admin', 'superadmin'].includes(role) | |
| } | |