Open History to see the last commit
1import { 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);
13}
14
15export function isWindowsPlatform(platform: string): boolean {
16 return /^win(dows)?/i.test(platform);
17}
18
19export function normalizeSearchText(value: string): string {
20 return value.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase().replace(/\s+/g, " ").trim();
21}
22
23export function getLocalFileManagerName(platform: string): string {
24 if (isMacPlatform(platform)) {
25 return "Finder";
26 }
27 if (isWindowsPlatform(platform)) {
28 return "File Explorer";
29 }
30 return "Files";
31}
32
33export function randomHex(byteLength: number): string {
34 return Encoding.encodeHex(globalThis.crypto.getRandomValues(new Uint8Array(byteLength)));
35}
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)}`;
43}
44
45export const newProjectId = (): ProjectId => ProjectId.make(randomUUID());
46
47export const newThreadId = (): ThreadId => ThreadId.make(randomUUID());
48
49export const newDraftId = (): DraftId => DraftId.make(randomUUID());
50
51export const newMessageId = (): MessageId => MessageId.make(randomUUID());