Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
/**
|
|
* Pure presentation helpers for the wallet & billing screens. No network, no
|
|
* secrets, no local money arithmetic beyond display formatting — every amount
|
|
* on the wire is already a server-authoritative integer (microdollars for the
|
|
* wallet, cents for invoices) and these helpers only render it.
|
|
*/
|
|
|
|
const MICRODOLLARS_PER_USD = 1_000_000;
|
|
const CENTS_PER_UNIT = 100;
|
|
|
|
/** Signed USD from integer microdollars, e.g. -1_500_000 → "-$1.50". */
|
|
export function formatMicrosSigned(micros: number | undefined | null): string {
|
|
const value = (micros ?? 0) / MICRODOLLARS_PER_USD;
|
|
const sign = value > 0 ? "+" : "";
|
|
return `${sign}$${value.toFixed(2)}`;
|
|
}
|
|
|
|
/** Display-only USD from an integer-cents amount, e.g. 2599 → "$25.99". */
|
|
export function formatCents(
|
|
cents: number | undefined | null,
|
|
currency = "USD",
|
|
): string {
|
|
const value = (cents ?? 0) / CENTS_PER_UNIT;
|
|
const symbol = currency.toUpperCase() === "USD" ? "$" : `${currency.toUpperCase()} `;
|
|
return `${symbol}${value.toFixed(2)}`;
|
|
}
|
|
|
|
/** Compact human date from an ISO-8601 string, e.g. "Sep 8, 2026". "" when blank. */
|
|
export function formatDate(iso: string | null | undefined): string {
|
|
if (!iso) return "";
|
|
const parsed = Date.parse(iso);
|
|
if (!Number.isFinite(parsed)) return "";
|
|
const d = new Date(parsed);
|
|
const months = [
|
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
|
|
] as const;
|
|
return `${months[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`;
|
|
}
|
|
|
|
/** Title-case a lower_snake or lowercase status token, e.g. "past_due" → "Past due". */
|
|
export function formatStatus(status: string | null | undefined): string {
|
|
const raw = (status ?? "").trim();
|
|
if (!raw) return "Unknown";
|
|
const spaced = raw.replace(/[_-]+/g, " ");
|
|
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
|
}
|