Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

utils.ts

32 lines1.0 KB

1import { CommandId, MessageId, ProjectId, ThreadId } from "@t3tools/contracts";
2import { type CxOptions, cx } from "class-variance-authority";
3import { twMerge } from "tailwind-merge";
4import * as Random from "effect/Random";
5import * as Effect from "effect/Effect";
6​
7export function cn(...inputs: CxOptions) {
8 return twMerge(cx(inputs));
9}
10​
11export function isMacPlatform(platform: string): boolean {
12 return /mac|iphone|ipad|ipod/i.test(platform);
14​
15export function isWindowsPlatform(platform: string): boolean {
16 return /^win(dows)?/i.test(platform);
18​
19export function randomUUID(): string {
20 if (typeof crypto.randomUUID === "function") {
21 return crypto.randomUUID();
22 }
23 return Effect.runSync(Random.nextUUIDv4);
25​
26export const newCommandId = (): CommandId => CommandId.makeUnsafe(randomUUID());
27​
28export const newProjectId = (): ProjectId => ProjectId.makeUnsafe(randomUUID());
29​
30export const newThreadId = (): ThreadId => ThreadId.makeUnsafe(randomUUID());
31​
32export const newMessageId = (): MessageId => MessageId.makeUnsafe(randomUUID());