File size: 2,610 Bytes
90250c5 | 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | 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"]; |