Bin
2025-12-17 2b99d77d73ba568beff0a549534017caaad8a6de
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
export const isFlagEnabled = (id: string, flagList: Record<string, boolean>, defaultValue = false) => {
  if (id in flagList) {
    return flagList[id] ?? defaultValue;
  }
  return defaultValue;
};
 
export const formDataToJPO = (formData: FormData) => {
  if (formData instanceof FormData) {
    return Object.fromEntries(formData.entries());
  }
 
  return formData;
};
 
export const isDefined = <T>(value: T | undefined | null): value is T => {
  return value !== null && value !== undefined;
};
 
export const userDisplayName = (user: Record<string, string> = {}) => {
  if (!user) return "";
  let { firstName, lastName, first_name, last_name, username, email } = user;
 
  if (first_name) {
    firstName = first_name;
  }
  if (last_name) {
    lastName = last_name;
  }
 
  return firstName || lastName
    ? [firstName, lastName]
        .filter((n) => !!n)
        .join(" ")
        .trim()
    : username || email;
};
 
export const copyText = async (text: string) => {
  await navigator.clipboard.writeText(text);
};
 
export const formatFileSize = (bytes: number): string => {
  if (bytes === 0) return "0 Bytes";
  const k = 1024;
  const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB"];
  const i = Math.floor(Math.log(bytes) / Math.log(k));
  return `${Number.parseFloat((bytes / k ** i).toFixed(2))} ${sizes[i]}`;
};