Download src/lib/utils.ts from lljz66/api: direct link, hf CLI and curl.
- Browser
- Download file 2.61 kB
-
https://huggingface.co/spaces/lljz66/api/resolve/main/src/lib/utils.ts
- Command line
-
hf download hf://spaces/lljz66/api/src/lib/utils.ts
-
curl -L -o utils.ts https://huggingface.co/spaces/lljz66/api/resolve/main/src/lib/utils.ts
2.61 kB
| import { clsx, type ClassValue } from "clsx"; | |
| import { twMerge } from "tailwind-merge"; | |
| import { formatDistanceToNowStrict } from "date-fns"; | |
| export function cn(...inputs: ClassValue[]) { | |
| return twMerge(clsx(inputs)); | |
| } | |
| export function timeAgo(date: Date | string | number | null | undefined) { | |
| if (!date) return ""; | |
| const d = new Date(date); | |
| const diff = Date.now() - d.getTime(); | |
| if (diff < 60_000) return "just now"; | |
| return formatDistanceToNowStrict(d, { addSuffix: false }) | |
| .replace(" seconds", "s") | |
| .replace(" second", "s") | |
| .replace(" minutes", "m") | |
| .replace(" minute", "m") | |
| .replace(" hours", "h") | |
| .replace(" hour", "h") | |
| .replace(" days", "d") | |
| .replace(" day", "d") | |
| .replace(" months", "mo") | |
| .replace(" month", "mo") | |
| .replace(" years", "y") | |
| .replace(" year", "y"); | |
| } | |
| export function formatSalary(min?: number | null, max?: number | null, text?: string | null) { | |
| const k = (n: number) => (n >= 1000 ? `$${Math.round(n / 1000)}k` : `$${n}`); | |
| if (min && max && max >= min) return `${k(min)} – ${k(max)}`; | |
| if (min) return `${k(min)}+`; | |
| if (max) return `Up to ${k(max)}`; | |
| return text?.trim() || ""; | |
| } | |
| export function stripHtml(html: string) { | |
| return html | |
| .replace(/<\s*(br|\/p|\/div|\/li|\/h[1-6])\s*\/?>/gi, "\n") | |
| .replace(/<li[^>]*>/gi, "• ") | |
| .replace(/<[^>]+>/g, " ") | |
| .replace(/ /g, " ") | |
| .replace(/&/g, "&") | |
| .replace(/</g, "<") | |
| .replace(/>/g, ">") | |
| .replace(/"/g, '"') | |
| .replace(/'|’|'/g, "'") | |
| .replace(/[ \t]+/g, " ") | |
| .replace(/\n\s*\n\s*\n+/g, "\n\n") | |
| .trim(); | |
| } | |
| export function initials(name: string) { | |
| return name | |
| .split(/\s+/) | |
| .filter(Boolean) | |
| .slice(0, 2) | |
| .map((p) => p[0]?.toUpperCase()) | |
| .join(""); | |
| } | |
| const PALETTE = [ | |
| ["#ffe4e0", "#d9482b"], | |
| ["#e0ecff", "#2f6df0"], | |
| ["#e3f6e8", "#1f8a4c"], | |
| ["#fff1d6", "#b9770e"], | |
| ["#efe3ff", "#7a3fd1"], | |
| ["#dff5f5", "#1a8a8a"], | |
| ["#ffe3f1", "#c93a84"], | |
| ]; | |
| export function colorFor(str: string) { | |
| let h = 0; | |
| for (let i = 0; i < str.length; i++) h = (h * 31 + str.charCodeAt(i)) >>> 0; | |
| return PALETTE[h % PALETTE.length]; | |
| } | |
| export const STATUSES = [ | |
| { key: "saved", label: "Saved", dot: "#a3a3a3" }, | |
| { key: "queued", label: "Ready to apply", dot: "#8b5cf6" }, | |
| { key: "applied", label: "Applied", dot: "#3b82f6" }, | |
| { key: "interview", label: "Interview", dot: "#f59e0b" }, | |
| { key: "offer", label: "Offer", dot: "#22c55e" }, | |
| { key: "rejected", label: "Rejected", dot: "#ef4444" }, | |
| ] as const; | |
| export type StatusKey = (typeof STATUSES)[number]["key"]; |