43 lines · 1.5 KB · TypeScript
RawDownload
import { CommandId, MessageId, ProjectId, ThreadId } from "@t3tools/contracts";import { type CxOptions, cx } from "class-variance-authority";import * as Encoding from "effect/Encoding";import { twMerge } from "tailwind-merge";import { DraftId } from "../composerDraftStore"; export function cn(...inputs: CxOptions) {  return twMerge(cx(inputs));} export function isMacPlatform(platform: string): boolean {  return /mac|iphone|ipad|ipod/i.test(platform);} export function isWindowsPlatform(platform: string): boolean {  return /^win(dows)?/i.test(platform);} export function isLinuxPlatform(platform: string): boolean {  return /linux/i.test(platform);} export function randomHex(byteLength: number): string {  return Encoding.encodeHex(globalThis.crypto.getRandomValues(new Uint8Array(byteLength)));} export function randomUUID(): string {  const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));  bytes[6] = (bytes[6]! & 0x0f) | 0x40;  bytes[8] = (bytes[8]! & 0x3f) | 0x80;  const hex = Encoding.encodeHex(bytes);  return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;} export const newCommandId = (): CommandId => CommandId.make(randomUUID()); export const newProjectId = (): ProjectId => ProjectId.make(randomUUID()); export const newThreadId = (): ThreadId => ThreadId.make(randomUUID()); export const newDraftId = (): DraftId => DraftId.make(randomUUID()); export const newMessageId = (): MessageId => MessageId.make(randomUUID());