@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"