⚠️ This is pre-release documentation for v3. For stable docs, visit v2.
Skip to content

@tmlmt/cooklang-parser / formatQuantityWithUnit

Function: formatQuantityWithUnit()

formatQuantityWithUnit(quantity, unit): string

Format a quantity with its unit to a string.

Parameters

quantity

The quantity to format

FixedValue | Range | undefined

unit

The unit to append (string, Unit object, or undefined)

string | Unit | undefined

Returns

string

The formatted string with quantity and unit

Example

typescript
formatQuantityWithUnit({ type: "fixed", value: { type: "decimal", decimal: 100 } }, "g"); // "100 g"
formatQuantityWithUnit({ type: "fixed", value: { type: "decimal", decimal: 2 } }, undefined); // "2"