@tmlmt/cooklang-parser / parseFixedValue
Function: parseFixedValue()
parseFixedValue(
input_str):DecimalValue|FractionValue|TextValue
Parse a single quantity value string into a fixed value.
A number-like input is parsed into a DecimalValue or FractionValue; anything else is returned as a TextValue. This is the value-level inverse of formatSingleValue.
Parameters
input_str
string
The raw value string (e.g. "1.5", "1/2", "a pinch")
Returns
DecimalValue | FractionValue | TextValue
The parsed fixed value
Example
typescript
parseFixedValue("1.5"); // { type: "decimal", decimal: 1.5 }
parseFixedValue("1/2"); // { type: "fraction", num: 1, den: 2 }
parseFixedValue("a pinch"); // { type: "text", text: "a pinch" }