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

utils.ts

53 lines1.7 KB

1import { CommandId, MessageId, ProjectId, ThreadId } from "@t3tools/contracts";
2import { type CxOptions, cx } from "class-variance-authority";
3import * as Encoding from "effect/Encoding";
4import { twMerge } from "tailwind-merge";
5import { DraftId } from "../composerDraftStore";
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 isLinuxPlatform(platform: string): boolean {
20 return /linux/i.test(platform);
22​
23export function getLocalFileManagerName(platform: string): string {
24 if (isMacPlatform(platform)) {
25 return "Finder";
26 }
27 if (isWindowsPlatform(platform)) {
28 return "Explorer";
29 }
30 return "Files";
32​
33export function randomHex(byteLength: number): string {
34 return Encoding.encodeHex(globalThis.crypto.getRandomValues(new Uint8Array(byteLength)));
36​
37export function randomUUID(): string {
38 const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
39 bytes[6] = (bytes[6]! & 0x0f) | 0x40;
40 bytes[8] = (bytes[8]! & 0x3f) | 0x80;
41 const hex = Encoding.encodeHex(bytes);
42 return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
44​
45export const newCommandId = (): CommandId => CommandId.make(randomUUID());
46​
47export const newProjectId = (): ProjectId => ProjectId.make(randomUUID());
48​
49export const newThreadId = (): ThreadId => ThreadId.make(randomUUID());
50​
51export const newDraftId = (): DraftId => DraftId.make(randomUUID());
52​
53export const newMessageId = (): MessageId => MessageId.make(randomUUID());