MCPcopy Index your code
hub / github.com/simstudioai/sim / formatCreditCost

Function formatCreditCost

apps/sim/lib/billing/credits/conversion.ts:38–54  ·  view source on GitHub ↗
(
  dollars: number | null | undefined,
  opts?: { emptyForZeroOrLess?: boolean }
)

Source from the content-addressed store, hash-verified

36 * the trace view wants `undefined` so it can hide the chip entirely.
37 */
38export function formatCreditCost(
39 dollars: number | null | undefined,
40 opts?: { emptyForZeroOrLess?: boolean }
41): string | undefined {
42 if (dollars === undefined || dollars === null || !Number.isFinite(dollars)) {
43 return opts?.emptyForZeroOrLess ? undefined : '—'
44 }
45
46 const credits = dollarsToCredits(dollars)
47
48 if (credits <= 0) {
49 if (dollars > 0) return '<1 credit'
50 return opts?.emptyForZeroOrLess ? undefined : '0 credits'
51 }
52
53 return `${credits.toLocaleString()} ${credits === 1 ? 'credit' : 'credits'}`
54}
55
56/**
57 * Splits a set of cost components into integer credits that sum *exactly* to

Callers 3

formatCostFunction · 0.90
conversion.test.tsFile · 0.90
formatCostAmountFunction · 0.90

Calls 1

dollarsToCreditsFunction · 0.85

Tested by

no test coverage detected