- Replace manual UUID byte formatting fallback in `apps/web/src/lib/utils.ts` - Use `Effect.runSync(Random.nextUUIDv4)` when `crypto.randomUUID` is unavailable
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { CommandId, MessageId, ProjectId, ThreadId } from "@t3tools/contracts";
|
|
import { type CxOptions, cx } from "class-variance-authority";
|
|
import { twMerge } from "tailwind-merge";
|
|
import * as Random from "effect/Random";
|
|
import * as Effect from "effect/Effect";
|
|
|
|
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 randomUUID(): string {
|
|
if (typeof crypto.randomUUID === "function") {
|
|
return crypto.randomUUID();
|
|
}
|
|
return Effect.runSync(Random.nextUUIDv4);
|
|
}
|
|
|
|
export const newCommandId = (): CommandId => CommandId.makeUnsafe(randomUUID());
|
|
|
|
export const newProjectId = (): ProjectId => ProjectId.makeUnsafe(randomUUID());
|
|
|
|
export const newThreadId = (): ThreadId => ThreadId.makeUnsafe(randomUUID());
|
|
|
|
export const newMessageId = (): MessageId => MessageId.makeUnsafe(randomUUID());
|