@tmlmt/cooklang-parser / getEffectiveChoices
Function: getEffectiveChoices()
getEffectiveChoices(
recipe,variant?):RecipeChoices
Returns the effective choices for a recipe given a variant selection.
When a named variant is active, this scans ingredient alternatives whose note contains the variant name (case-insensitive substring match) and returns a RecipeChoices object with auto-selected alternatives.
For inline alternatives: auto-selects the first alternative whose note matches the variant name.
For grouped alternatives: auto-selects the first subgroup that has any alternative whose note matches the variant name.
Parameters
recipe
The Recipe instance
variant?
string
The active variant name, or undefined/* for defaults
Returns
A RecipeChoices with the variant set and auto-selected alternatives
Example
typescript
const recipe = new Recipe(cooklangText);
const choices = getEffectiveChoices(recipe, "vegan");
const ingredients = recipe.getIngredientQuantities({ choices });