From 06c003fc68bd621c83a67c636351a45a2cff13fc Mon Sep 17 00:00:00 2001 From: arsam Date: Fri, 18 Sep 2026 23:11:16 +0330 Subject: [PATCH] Import source: src/lib/utils Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality. --- src/lib/utils.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/lib/utils.ts diff --git a/src/lib/utils.ts b/src/lib/utils.ts new file mode 100644 index 0000000..ba0ae50 --- /dev/null +++ b/src/lib/utils.ts @@ -0,0 +1,26 @@ +import { type ClassValue, clsx } from "clsx"; +import { twMerge } from "tailwind-merge"; + +export function cn(...inputs: ClassValue[]) { + return twMerge(clsx(inputs)); +} + +export function titleize(value: string) { + return value.replace(/[-_]/g, " ").replace(/\b\w/g, (letter) => letter.toUpperCase()); +} + +export function formatBytes(bytes: number) { + const units = ["B", "KB", "MB", "GB", "TB"]; + let size = bytes; + let unit = 0; + while (size >= 1024 && unit < units.length - 1) { + size /= 1024; + unit += 1; + } + return `${size.toFixed(size >= 10 || unit === 0 ? 0 : 1)} ${units[unit]}`; +} + +export function percent(value: number, total: number) { + if (total <= 0) return 0; + return Math.min(100, Math.max(0, Math.round((value / total) * 100))); +}