Pricing

The pricing module says which currency a reader is most likely to think in and writes prices in it (DS1/0-face/pricing.ts). The amounts come from the product’s billing; this only says how they read. It writes them through Formatting’s formatMoney, so the currency’s decimals and the language’s separators are right.

import { formatPrice, getPriceCurrency, getPriceLabel } from "@0001-labs/design-system-1";
getPriceCurrency({ language: "da" }); // "DKK"
getPriceCurrency({ language: "en", country: "GB" }); // "GBP"
getPriceLabel({ language: "ja" }); // "¥"
formatPrice(1999, { language: "en", minor: true }); // "$19.99"
formatPrice(1200, { language: "ja" }); // "¥1,200"
formatPrice(5, { currency: "EUR", language: "de" }); // "5,00 €"

getPriceCurrency({ language?, country? }) gives an ISO 4217 code: the country’s currency when the country is known (US, GB, JP, CN, KR, as two or three letters), else the language’s, else USD. Without a language, the current language’s.

LanguageCurrency
daDKK
de, es, fi, fr, it, ptEUR
enUSD
isISK
jaJPY
koKRW
nb, nn, noNOK
pt-BRBRL
svSEK
zhCNY
  • getPriceLabel({ language?, country? }) gives the reader’s currency as a short label: kr. for the Nordic crowns, €, $, £, ¥, ₩, R$; any other currency as the symbol the language writes it with.
  • formatPrice(amount, options?) writes an amount in currency, or in the reader’s currency when none is given. It takes the money options: minor for amounts in cents, display, whole.

A price a person pays is in the currency the product charges, not a guess from their language: pass currency whenever the billing names one, and keep the reader’s currency for estimates and labels.