Initial commit: Apothecary v0.4.0
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
// fmt.* — verbatim port from primitives.jsx
|
||||
export const fmt = {
|
||||
g(n: number | null | undefined): string {
|
||||
if (n == null) return "—";
|
||||
const trimmed = (+n).toFixed(2).replace(/\.?0+$/, "");
|
||||
return `${trimmed || "0"} g`;
|
||||
},
|
||||
money(n: number | null | undefined): string {
|
||||
if (n == null) return "—";
|
||||
return `$${(+n).toFixed(2)}`;
|
||||
},
|
||||
moneyShort(n: number | null | undefined): string {
|
||||
if (n == null) return "—";
|
||||
return n >= 100 ? `$${Math.round(n)}` : `$${(+n).toFixed(2)}`;
|
||||
},
|
||||
pct(n: number | null | undefined): string {
|
||||
if (n == null) return "—";
|
||||
return `${(+n).toFixed(1)}%`;
|
||||
},
|
||||
date(s: string | null | undefined): string {
|
||||
if (!s) return "—";
|
||||
const d = new Date(s);
|
||||
return d.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" });
|
||||
},
|
||||
dateShort(s: string | null | undefined): string {
|
||||
if (!s) return "—";
|
||||
const d = new Date(s);
|
||||
return d.toLocaleDateString("en-US", { month: "short", day: "numeric" });
|
||||
},
|
||||
daysAgo(s: string | null | undefined): string {
|
||||
if (!s) return "—";
|
||||
const ms = Date.now() - new Date(s).getTime();
|
||||
const d = Math.floor(ms / 86_400_000);
|
||||
if (d === 0) return "today";
|
||||
if (d === 1) return "yesterday";
|
||||
if (d < 30) return `${d}d ago`;
|
||||
if (d < 365) return `${Math.floor(d / 30)}mo ago`;
|
||||
return `${Math.floor(d / 365)}y ago`;
|
||||
},
|
||||
};
|
||||
|
||||
export const TYPE_GLYPHS: Record<string, string> = {
|
||||
Flower: "✿",
|
||||
Concentrate: "◆",
|
||||
Edible: "◐",
|
||||
Vaporizer: "▢",
|
||||
"Pre-roll": "│",
|
||||
Tincture: "◯",
|
||||
};
|
||||
Reference in New Issue
Block a user