-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathutils.ts
More file actions
40 lines (31 loc) · 1.23 KB
/
utils.ts
File metadata and controls
40 lines (31 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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());
export const ensureSentenceEnds = (value: string): string => {
const trimmed = value.trim();
if ([".", "!", "?"].includes(trimmed.at(-1) ?? "")) {
return trimmed;
}
return `${trimmed}.`;
};