Examples: scaling recipes
Pre-requisite
To be able to scale, a Recipe
must have its servings
property set, which is done by the parser when it encounters one of the following tags in the recipe's frontmatter: servings
, serves
or yield
:
json
---
servings: 2
[- or -]serves: 2
[- or -]yield: 2
---
The rest of this guide assumes that you have set one of the above, and will assume a servings
value of 2
Scaling by a factor
Use the scaleBy()
method.
typescript
const recipe = Recipe(`...`)
const scaledRecipe = recipe.scaleBy(2)
All the ingredients with numerical quantities have their quantities multiplied by 2, and the metadata and servings
value will also be multiplied by 2
Scaling to a specific number of servings
Use the scaleTo()
method.
typescript
const recipe = Recipe(`...`)
const scaledRecipe = recipe.scaleTo(4)
// In this case, this is equivalent to
// const scaledRecipe = recipe.scaleBy(2)
All the ingredients with numerical quantities have their quantities adjusted by a factor of 4/2 in this case, and the metadata and servings
value will also be multiplied by the same factor.