Helper Functions

LiveMarket SDK provides a few helper functions to help you work with the received data.

Formatters

formatPrice: string

Returns a formatted price with currency based on provided locale. Uses Intl.NumberFormat to format the currency.

import { formatPrice } from 'livemarket-sdk';

const formattedPrice = formatPrice(35.99, 'EUR', 'en-US'); // €35.99

Parameters

amount: number

Amount of money.

currency: string

Currency code.

(optional) locale: string

Locale to format the currency in. Can be either a 2-letter language code which can be obtain from client.getLanguage() or a BCP-47 language tag. Defaults to en-US.

formatPriceRange: string

Returns a formatted price range. It will return a single price, if start and stop properties of the price range are equal. Uses formatPrice.

import { formatPriceRange } from 'livemarket-sdk';

// ...

const product = await client.fetchProductById('...');

const formattedPriceRange = formatPriceRange(product.pricing.priceRange, 'en-US'); // €32.99 - €35.99

Parameters

range: TaxedMoneyRange

Range of prices to format.

(optional) locale: string

Locale to format the price range in.