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

@tmlmt/cooklang-parser / formatUnit

Function: formatUnit() ​

formatUnit(unit): string

Format a unit to a string. Handles both plain string units and Unit objects.

Parameters ​

unit ​

string | Unit | undefined

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

Returns ​

string

The formatted unit string, or empty string if undefined

Example ​

typescript
formatUnit("g"); // "g"
formatUnit({ name: "grams" }); // "grams"
formatUnit(undefined); // ""