@tmlmt/cooklang-parser / hasAlternatives
Function: hasAlternatives()
hasAlternatives(
entry): entry is (IngredientQuantityGroup | IngredientQuantityAndGroup) & { alternatives: AlternativeIngredientRef[][] }
Type guard to check if an ingredient quantity entry has alternatives.
Parameters
entry
IngredientQuantityGroup | IngredientQuantityAndGroup
The quantity entry to check
Returns
entry is (IngredientQuantityGroup | IngredientQuantityAndGroup) & { alternatives: AlternativeIngredientRef[][] }
true if this entry has alternatives
Example
typescript
for (const entry of ingredient.quantities) {
if (hasAlternatives(entry)) {
// entry.alternatives is available and non-empty
for (const subgroup of entry.alternatives) {
// Each subgroup is one "or" choice; items within are combined with "+"
for (const alt of subgroup) {
console.log(`Alternative ingredient index: ${alt.index}`);
}
}
}
}