Utilities

Utilities

Use Cardspark's server-safe helpers for Pokémon condition labels and USD display values.

Server-safe entrypoint

Import helpers directly from @cardspark/ui/utils in Server Components or shared modules. The same formatting helpers remain available from @cardspark/ui/core for compatibility, but that component entrypoint carries a Client Component boundary.

CardValue.tsx
import {  formatConditionLabel,  formatCurrency} from "@cardspark/ui/utils"; export default function CardValue({  condition,  value}: {  condition: string;  value: number;}) {  return (    <p>      {formatConditionLabel(condition, "code-label")} · {formatCurrency(value)}    </p>  );}

Condition labels

formatConditionLabel renders a condition as a compact code, full label, or combined code and label. getConditionAcronym returns the same compact code used by the default mode.

condition-labels.ts
formatConditionLabel("Near Mint");// "NM" formatConditionLabel("Near Mint", "label");// "Near Mint" formatConditionLabel("Near Mint", "code-label");// "NM - Near Mint" getConditionAcronym("Lightly Played");// "LP"

Known Pokémon conditions use Cardspark's standard abbreviations. Numeric and grader-prefixed grades are preserved, while unrecognized labels fall back to initials from their first two words.

USD values

formatCurrency, formatDeltaFromReference, and parseCurrencyLabel support Cardspark's current USD-focused package contract.

money.ts
formatCurrency(214.75);// "$214.75" formatDeltaFromReference(214.75, 200);// "+$14.75 (7.4%)" parseCurrencyLabel("Market value: $1,024.50");// 1024.5

formatCurrency currently uses the en-US locale and USD currency with two decimal places. These helpers do not yet accept locale or currency options.

API reference

ExportSignatureBehavior
formatConditionLabel(condition: string, mode?: ConditionLabelMode) => stringFormats a condition as a code, label, or combined value. The mode defaults to "code".
getConditionAcronym(condition: string) => stringReturns the compact code used by the default condition-label mode.
formatCurrency(value: number) => stringFormats a number as an en-US USD amount with exactly two decimal places.
formatDeltaFromReference(value: number, referenceValue: number) => stringFormats the signed USD difference and absolute percentage change from a reference value.
parseCurrencyLabel(value: string) => number | undefinedReturns the first comma-separated signed number found in a display label.
ConditionLabelMode"code" | "label" | "code-label"Controls compact, full, or combined condition-label output.