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

utils.ts

39 lines1.2 KB

1import { CommandId, MessageId, ProjectId, ThreadId } from "@workbench/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";
6import { DraftId } from "../composerDraftStore";
7​
8export function cn(...inputs: CxOptions) {
9 return twMerge(cx(inputs));
11​
12export function isMacPlatform(platform: string): boolean {
13 return /mac|iphone|ipad|ipod/i.test(platform);
15​
16export function isWindowsPlatform(platform: string): boolean {
17 return /^win(dows)?/i.test(platform);
19​
20export function isLinuxPlatform(platform: string): boolean {
21 return /linux/i.test(platform);
23​
24export function randomUUID(): string {
25 if (typeof crypto.randomUUID === "function") {
26 return crypto.randomUUID();
27 }
28 return Effect.runSync(Random.nextUUIDv4);
30​
31export const newCommandId = (): CommandId => CommandId.make(randomUUID());
32​
33export const newProjectId = (): ProjectId => ProjectId.make(randomUUID());
34​
35export const newThreadId = (): ThreadId => ThreadId.make(randomUUID());
36​
37export const newDraftId = (): DraftId => DraftId.make(randomUUID());
38​
39export const newMessageId = (): MessageId => MessageId.make(randomUUID());