shelving/util/currencymodule

Validate ISO 4217 currency codes and retrieve display metadata (symbol, smallest unit step) using the runtime's built-in Intl API. The list of supported codes comes from Intl.supportedValuesOf("currency") so it stays current without a bundled lookup table.

Usage

Validating a code

ts
import { getCurrencyCode, requireCurrencyCode, CURRENCY_CODES } from "shelving/util";

getCurrencyCode("gbp");   // "GBP"
getCurrencyCode("XYZ");   // undefined

requireCurrencyCode("GBP"); // "GBP"
requireCurrencyCode("XYZ"); // throws RequiredError

CURRENCY_CODES.includes("EUR"); // true

Display symbol and step

ts
import { getCurrencySymbol, getCurrencyStep } from "shelving/util";

getCurrencySymbol("GBP"); // "£"
getCurrencySymbol("USD"); // "$"
getCurrencySymbol("JPY"); // "¥"

getCurrencyStep("USD"); // 0.01
getCurrencyStep("JPY"); // 1

Functions

Go

getCurrencyCode()function

Normalise a value to a valid ISO 4217 CurrencyCode, or undefined if it isn't a supported currency.

getCurrencyCode(value: string): CurrencyCode | undefined
Go

requireCurrencyCode()function

Normalise a value to a valid ISO 4217 CurrencyCode, or throw RequiredError if it isn't a supported currency.

requireCurrencyCode(value: string, caller: AnyCaller = requireCurrencyCode): CurrencyCode
Go

getCurrencySymbol()function

Get the display symbol used for a currency.

getCurrencySymbol(currency: CurrencyCode, caller: AnyCaller = getCurrencySymbol): string
Go

getCurrencyStep()function

Get the "step" value for a currency, i.e. the smallest fractional unit that is used for that currency.

getCurrencyStep(currency: CurrencyCode, caller: AnyCaller = getCurrencyStep): number

Types

Go

CurrencyCodetype

ISO 4217 currency code, e.g. GBP or USD.

string

Constants

Go

CURRENCY_CODESconstant

Array of all ISO 4217 currency codes supported by the current runtime's Intl implementation.

CURRENCY_CODES: ImmutableArray<CurrencyCode>