Import source: src/lib/utils

Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
This commit is contained in:
arsam
2026-09-18 23:11:16 +03:30
parent 63694b6be4
commit 06c003fc68
+26
View File
@@ -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)));
}