forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
53 lines (45 loc) · 1.28 KB
/
Copy pathutils.ts
File metadata and controls
53 lines (45 loc) · 1.28 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
41
42
43
44
45
46
47
48
49
50
51
52
53
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export async function fetcher<JSON = any>(
input: RequestInfo,
init?: RequestInit,
): Promise<JSON> {
const res = await fetch(input, init);
if (!res.ok) {
const json = await res.json();
if (json.error) {
const error = new Error(json.error) as Error & {
status: number;
};
error.status = res.status;
throw error;
} else {
throw new Error("An unexpected error occurred");
}
}
return res.json();
}
export function formatDate(input: string | number | Date): string {
const date = new Date(input);
return date.toLocaleDateString("en-US", {
month: "long",
day: "numeric",
year: "numeric",
});
}
export const arraysAreEqual = (arr1: number[], arr2: number[]): boolean =>
arr1.length === arr2.length &&
arr1.every((value, index) => value === arr2[index]);
export function nullableCompatibleEqualityCheck<T>(
naiveEqualityCheck: (a: T, b: T) => boolean,
a: T | null | undefined,
b: T | null | undefined,
): boolean {
if (a === null || a === undefined || b === null || b === undefined) {
return a === b;
}
return naiveEqualityCheck(a, b);
}