OpChan/src/lib/utils.ts

25 lines
622 B
TypeScript
Raw Normal View History

2025-08-30 18:34:50 +05:30
import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';
2025-04-15 16:28:03 +05:30
export function cn(...inputs: ClassValue[]) {
2025-08-30 18:34:50 +05:30
return twMerge(clsx(inputs));
2025-04-15 16:28:03 +05:30
}
export function bytesToHex(bytes: Uint8Array): string {
return Array.from(bytes)
.map(b => b.toString(16).padStart(2, '0'))
.join('');
}
export function hexToBytes(hex: string): Uint8Array {
const bytes = new Uint8Array(hex.length / 2);
for (let i = 0; i < hex.length; i += 2) {
bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
}
return bytes;
2025-08-29 15:29:20 +05:30
}
export function generateStringId(): string {
return crypto.randomUUID();
2025-08-30 18:34:50 +05:30
}