@molecule/app-currency-display-vue

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-vue

npm · Source on GitHub

How it works

@molecule/app-currency-display-vue 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.

import { defineComponent, h } from 'vue'
import { CurrencyDisplay, formatCurrency } from '@molecule/app-currency-display-vue'

const Price = defineComponent({
  setup() {
    // Basic amount
    return () => h(CurrencyDisplay, { amount: 49.99, currency: 'USD', size: 'lg' })
  },
})

// With original price and savings chip
h(CurrencyDisplay, { amount: 29.99, originalAmount: 49.99, currency: 'USD', showSavings: true })

// Compact notation: "$29.99K"
h(CurrencyDisplay, { amount: 29990, currency: 'USD', compact: true, size: 'xl' })

// Plain string utility
const label = formatCurrency(1234.56, 'EUR', 'de-DE') // "1.234,56 €"

Works with: @molecule/app-ui, @molecule/app-ui-vue, @molecule/app-vue

Reference

Vue currency display and formatting utilities.

Exports:

  • formatCurrency(amount, currency?, locale?) — plain string via Intl.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.ts JSDoc, not this file.

Quick Start

import { defineComponent, h } from 'vue'
import { CurrencyDisplay, formatCurrency } from '@molecule/app-currency-display-vue'

const Price = defineComponent({
  setup() {
    // Basic amount
    return () => h(CurrencyDisplay, { amount: 49.99, currency: 'USD', size: 'lg' })
  },
})

// With original price and savings chip
h(CurrencyDisplay, { amount: 29.99, originalAmount: 49.99, currency: 'USD', showSavings: true })

// Compact notation: "$29.99K"
h(CurrencyDisplay, { amount: 29990, currency: 'USD', compact: true, size: 'xl' })

// Plain string utility
const label = formatCurrency(1234.56, 'EUR', 'de-DE') // "1.234,56 €"

Type

feature

Installation

npm install @molecule/app-currency-display-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue

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). Pass amount / 100 if 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

Display a monetary amount with optional original price (strikethrough) and a "saved X%" chip. Uses Intl.NumberFormat under the hood.

Use the formatCurrency / formatCurrencyCompact utilities directly when you just need a string without rendering chrome.

const CurrencyDisplay: DefineComponent<
  ExtractPropTypes<{
    amount: { type: NumberConstructor; required: true }
    originalAmount: NumberConstructor
    currency: { type: StringConstructor; default: string }
    locale: StringConstructor
    size: { type: PropType<CurrencyDisplayProps['size']>; default: string }
    compact: BooleanConstructor
    showSavings: { type: BooleanConstructor; default: boolean }
    savingsLabel: { type: PropType<(saved: number, pct: number) => string> }
    className: StringConstructor
  }>,
  () => VNode,
  {},
  {},
  {},
  ComponentOptionsMixin,
  ComponentOptionsMixin,
  {},
  string,
  PublicProps,
  Readonly<
    ExtractPropTypes<{
      amount: { type: NumberConstructor; required: true }
      originalAmount: NumberConstructor
      currency: { type: StringConstructor; default: string }
      locale: StringConstructor
      size: { type: PropType<CurrencyDisplayProps['size']>; default: string }
      compact: BooleanConstructor
      showSavings: { type: BooleanConstructor; default: boolean }
      savingsLabel: { type: PropType<(saved: number, pct: number) => string> }
      className: StringConstructor
    }>
  > &
    Readonly<{}>,
  {
    size: 'sm' | 'md' | 'lg' | 'xl' | undefined
    compact: boolean
    currency: string
    showSavings: boolean
  },
  {},
  {},
  {},
  string,
  ComponentProvideOptions,
  true,
  {},
  any
>

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-vue ^1.1.0
  • @molecule/app-vue ^3.5.0 || ^4.0.0
  • vue ^3.4.0

Runtime Dependencies

  • @molecule/app-ui
  • @molecule/app-ui-vue
  • @molecule/app-vue
  • vue

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.