@molecule/app-currency-display-svelte
Feature · currency-display · App (browser) · v1.1.1 · Apache-2.0
Currency amount formatting + CurrencyDisplay with optional original price + savings badge
npm install @molecule/app-currency-display-svelteHow it works
@molecule/app-currency-display-svelte is a ready-made currency-display feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
<script lang="ts">
import { CurrencyDisplay, formatCurrency } from '@molecule/app-currency-display-svelte'
// Plain string utility
const label = formatCurrency(1234.56, 'EUR', 'de-DE') // "1.234,56 €"
</script>
<!-- Basic amount -->
<CurrencyDisplay amount={49.99} currency="USD" size="lg" />
<!-- With original price and savings chip -->
<CurrencyDisplay amount={29.99} originalAmount={49.99} currency="USD" showSavings />
<!-- Compact notation: "$29.99K" -->
<CurrencyDisplay amount={29990} currency="USD" compact size="xl" />Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte
Reference
Svelte currency display and formatting utilities — the Svelte counterpart of
@molecule/app-currency-display-react, with the same props and the same DOM.
Exports:
formatCurrency(amount, currency?, locale?)— plain string viaIntl.NumberFormat.formatCurrencyCompact(amount, currency?, locale?)— compact notation ($12.3K).CurrencyDisplay— rendered amount with optional strikethrough original price + savings chip.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
<script lang="ts">
import { CurrencyDisplay, formatCurrency } from '@molecule/app-currency-display-svelte'
// Plain string utility
const label = formatCurrency(1234.56, 'EUR', 'de-DE') // "1.234,56 €"
</script>
<!-- Basic amount -->
<CurrencyDisplay amount={49.99} currency="USD" size="lg" />
<!-- With original price and savings chip -->
<CurrencyDisplay amount={29.99} originalAmount={49.99} currency="USD" showSavings />
<!-- Compact notation: "$29.99K" -->
<CurrencyDisplay amount={29990} currency="USD" compact size="xl" />
Type
feature
Installation
npm install @molecule/app-currency-display-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
API
Interfaces
CurrencyDisplayProps
Props for CurrencyDisplay.
interface CurrencyDisplayProps {
/** Current amount in major units. */
amount: number
/** Optional original amount — rendered strikethrough to show a discount. */
originalAmount?: number
/** ISO 4217 currency code. */
currency?: string
/** Locale override. */
locale?: string
/** Display size. */
size?: 'sm' | 'md' | 'lg' | 'xl'
/** Compact notation (`$12.3K`) instead of full. */
compact?: boolean
/** Show a savings chip when `originalAmount > amount`. */
showSavings?: boolean
/** Custom savings label renderer. */
savingsLabel?: (saved: number, pct: number) => string
/** Extra classes. */
className?: string
}
Functions
formatCurrency(amount, currency, locale)
Formats a numeric amount as currency using Intl.NumberFormat.
function formatCurrency(amount: number, currency?: string, locale?: string): string
amount— Amount in major units (e.g. dollars, not cents). Passamount / 100if your stored value is in cents.currency— ISO 4217 currency code. Defaults to"USD".locale— BCP 47 locale tag. Defaults to the runtime default (undefined).
Returns: Formatted currency string.
formatCurrencyCompact(amount, currency, locale)
Formats a numeric amount as currency in a compact form (e.g. "$12.3K").
Uses Intl.NumberFormat with notation: 'compact' when supported.
function formatCurrencyCompact(amount: number, currency?: string, locale?: string): string
amount— Amount in major units.currency— ISO 4217 currency code. Defaults to"USD".locale— BCP 47 locale tag. Defaults to the runtime default (undefined).
Returns: Formatted compact currency string.
Constants
CurrencyDisplay
const CurrencyDisplay: LegacyComponentType
Injection Notes
Requirements
Peer dependencies:
@molecule/app-svelte^3.5.0 || ^4.0.0@molecule/app-ui^1.0.1@molecule/app-ui-svelte^1.1.0svelte^5.0.0
Runtime Dependencies
@molecule/app-svelte@molecule/app-ui@molecule/app-ui-sveltesvelte
Amounts are in MAJOR units (dollars, not cents) — divide stored cents by
100 first. showSavings defaults to true, so a savings chip appears
whenever originalAmount > amount; pass showSavings={false} for plain
was/now price display. Formatting is Intl.NumberFormat (locale-aware,
no i18n keys needed); savingsLabel(saved, pct) lets you localize the
chip text.