{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "format",
  "title": "Format",
  "description": "Money in integer minor units, relative days and times, and plain-text extraction for truncated cells.",
  "files": [
    {
      "path": "registry/khaeli/lib/format.ts",
      "content": "/**\n * Money is integer minor units everywhere in this codebase. Formatting works\n * in integer cents/remainder arithmetic rather than dividing by 100 as a\n * float, so large amounts never pick up floating-point rounding noise.\n */\nexport function formatCents(cents: number, currency: string): string {\n  const negative = cents < 0\n  const absolute = Math.abs(cents)\n  const major = Math.trunc(absolute / 100)\n  const minor = absolute % 100\n  const grouped = major.toLocaleString(\"en-SG\")\n  return `${currency} ${negative ? \"-\" : \"\"}${grouped}.${String(minor).padStart(2, \"0\")}`\n}\n\n\n/** Relative day count, e.g. 0 -> \"today\", 1 -> \"1 day\", 5 -> \"5 days\". */\nexport function formatRelativeDays(days: number): string {\n  if (days === 0) return \"today\"\n  return `${days} day${Math.abs(days) === 1 ? \"\" : \"s\"}`\n}\n\n/** Short relative timestamp for chips and meta lines: \"just now\", \"5 min ago\", \"3 h ago\", \"yesterday\", \"4 days ago\". */\nexport function formatRelativeTime(value: string): string {\n  const elapsed = Date.now() - new Date(value).getTime()\n  if (elapsed < 60_000) return \"just now\"\n  const minutes = Math.floor(elapsed / 60_000)\n  if (minutes < 60) return `${minutes} min ago`\n  const hours = Math.floor(minutes / 60)\n  if (hours < 24) return `${hours} h ago`\n  const days = Math.floor(hours / 24)\n  return days === 1 ? \"yesterday\" : `${days} days ago`\n}\n\n/**\n * The text of a node when it is plain text, for `title` on truncated\n * elements so the full value stays readable. Element children return\n * undefined: the caller that composed them owns the tooltip.\n */\nexport function plainText(node: unknown): string | undefined {\n  if (typeof node === \"string\") return node\n  if (typeof node === \"number\") return String(node)\n  return undefined\n}\n",
      "type": "registry:lib"
    }
  ],
  "type": "registry:lib"
}