@tmlmt/cooklang-parser / stringifyQuantityValue
Function: stringifyQuantityValue()
stringifyQuantityValue(
quantity):string
Stringify a quantity value back into its canonical Cooklang source form.
This is the inverse of parseQuantityValue: fractions render as num/den, decimals as their number, and ranges as min-max. Unlike formatQuantity, it does not apply any display formatting.
Parameters
quantity
The quantity to stringify
Returns
string
The canonical string representation
Example
typescript
stringifyQuantityValue({ type: "fixed", value: { type: "fraction", num: 1, den: 2 } }); // "1/2"
stringifyQuantityValue({ type: "range", min: { type: "decimal", decimal: 1 }, max: { type: "decimal", decimal: 2 } }); // "1-2"