Spaces:
Paused
Paused
| import clsx from 'clsx'; | |
| import { twMerge } from 'tailwind-merge'; | |
| export function cn(...inputs: any[]) { | |
| return twMerge(clsx(inputs)); | |
| } | |
| export function truncate(str: string, length: number = 100): string { | |
| if (str.length <= length) return str; | |
| return str.slice(0, length) + '...'; | |
| } | |
| export function formatDate(date: Date | string): string { | |
| const d = typeof date === 'string' ? new Date(date) : date; | |
| return d.toLocaleDateString('en-US', { | |
| year: 'numeric', | |
| month: 'short', | |
| day: 'numeric', | |
| }); | |
| } | |
| export function formatTime(date: Date | string): string { | |
| const d = typeof date === 'string' ? new Date(date) : date; | |
| return d.toLocaleTimeString('en-US', { | |
| hour: '2-digit', | |
| minute: '2-digit', | |
| }); | |
| } | |
| export function downloadFile(blob: Blob, filename: string): void { | |
| const url = window.URL.createObjectURL(blob); | |
| const link = document.createElement('a'); | |
| link.href = url; | |
| link.download = filename; | |
| document.body.appendChild(link); | |
| link.click(); | |
| document.body.removeChild(link); | |
| window.URL.revokeObjectURL(url); | |
| } | |
| export function formatFileSize(bytes: number): string { | |
| if (bytes === 0) return '0 Bytes'; | |
| const k = 1024; | |
| const sizes = ['Bytes', 'KB', 'MB', 'GB']; | |
| const i = Math.floor(Math.log(bytes) / Math.log(k)); | |
| return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i]; | |
| } | |
| export function formatNumber(num: number): string { | |
| return new Intl.NumberFormat('en-US').format(num); | |
| } | |
| export function getInitials(name: string): string { | |
| return name | |
| .split(' ') | |
| .map((n) => n[0]) | |
| .join('') | |
| .toUpperCase() | |
| .slice(0, 2); | |
| } | |
| export async function readFileAsArrayBuffer(file: File): Promise<ArrayBuffer> { | |
| return new Promise((resolve, reject) => { | |
| const reader = new FileReader(); | |
| reader.onload = (e) => { | |
| if (e.target?.result instanceof ArrayBuffer) { | |
| resolve(e.target.result); | |
| } else { | |
| reject(new Error('Failed to read file')); | |
| } | |
| }; | |
| reader.onerror = () => reject(new Error('File read error')); | |
| reader.readAsArrayBuffer(file); | |
| }); | |
| } | |
| export const COLORS = { | |
| primary: '#22c55e', // emerald-500 | |
| primaryDark: '#15803d', // emerald-700 | |
| background: '#0A0E27', | |
| backgroundLight: '#1a1f3a', | |
| text: '#f8fafc', | |
| textMuted: '#cbd5e1', | |
| border: '#334155', | |
| success: '#22c55e', | |
| error: '#ef4444', | |
| warning: '#f59e0b', | |
| info: '#3b82f6', | |
| }; | |