cg / hackerproducts

63 files · 5,740 lines · 159.1 KB — Next.js 15, React 19, TypeScript, PostgreSQL, Object Storage, plain CSS.

Quick jump: page.tsx / page.tsx / globals.css / schema.sql / package.json

root / src / lib / format.ts

src/lib/format.ts · 40 lines · 933 B← back to folder
1const ICON_COLORS = [
2 "#111111",
3 "#2563eb",
4 "#7c3aed",
5 "#059669",
6 "#ea580c",
7 "#dc2626",
8 "#0891b2",
9 "#4f46e5",
10 "#db2777",
11 "#65a30d",
12];
13
14export function formatDisplayDate(iso: string | Date): string {
15 const date = typeof iso === "string" ? new Date(iso) : iso;
16 return new Intl.DateTimeFormat("en-US", {
17 month: "long",
18 day: "numeric",
19 year: "numeric",
20 timeZone: "UTC",
21 }).format(date);
22}
23
24export function getDateKey(iso: string | Date): string {
25 const date = typeof iso === "string" ? new Date(iso) : iso;
26 return date.toISOString().slice(0, 10);
27}
28
29export function getFallbackIconColor(seed: string): string {
30 let hash = 0;
31 for (let i = 0; i < seed.length; i++) {
32 hash = (hash * 31 + seed.charCodeAt(i)) >>> 0;
33 }
34 return ICON_COLORS[hash % ICON_COLORS.length];
35}
36
37export function formatStarCount(count: number): string {
38 return new Intl.NumberFormat("en-US").format(count);
39}
40
cg / hackerproducts — hacker products