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

@tmlmt/cooklang-parser / parseQuantityValue

Function: parseQuantityValue()

parseQuantityValue(input_str): FixedValue | Range

Parse a quantity string into a fixed value or a range.

A min-max input (where both sides are number-like) is parsed into a Range; otherwise the whole string is parsed as a single fixed value via parseFixedValue. This is the value-level inverse of stringifyQuantityValue.

Parameters

input_str

string

The raw quantity string (e.g. "1", "1/2", "1-2")

Returns

FixedValue | Range

The parsed quantity

Example

typescript
parseQuantityValue("2"); // { type: "fixed", value: { type: "decimal", decimal: 2 } }
parseQuantityValue("1-2"); // { type: "range", min: {...}, max: {...} }