ChemPal Documentation - v1.6.0
    Preparing search index...

    Module helpers/price

    Formatters - Helpers

    formatDisplayPrice

    Formats a product or variant price for display, converting into the user's selected currency when a USD anchor is available.

    getUnitPrice

    Computes a product's price per base unit as a currency-stable number for sorting and filtering — the USD price (or raw price when there's no USD anchor) divided by the quantity normalized to its cost base unit (grams for mass, millilitres for volume, pieces for countable units; see toCostBaseQuantity). Returns undefined when there's no price, no quantity, or the unit can't be converted, so the value never becomes NaN.

    formatUnitPrice

    Formats a product's price per base unit for display, e.g. "$0.08/g" or "$19.99/pcs". Resolves the per-unit amount via resolveUnitPrice, then renders it at two decimal places, collapsing any positive unit price below one cent to "<$0.01/{unit}" (see formatPerUnitPrice) to keep the column narrow. The unrounded value is available via formatUnitPriceExact for a hover tooltip. Returns "" when there's no price or the quantity/unit can't be converted.

    formatUnitPriceExact

    Formats a product's price per base unit at full precision — up to four decimal places, with no sub-cent collapse — for use as the hover tooltip behind the rounded formatUnitPrice display, so a value shown as "<$0.01/g" or "$0.07/g" reveals its actual "$0.0035/g" / "$0.072/g" on hover. Uses the same resolved amount as the display formatter (see resolveUnitPrice). Returns "" when there's no price or the quantity/unit can't be converted.

    Modules

    <internal>