⚠️ This is pre-release documentation for v3. For stable docs, visit v2.
Skip to content

@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

The quantity entry to check

IngredientQuantityGroup | IngredientQuantityAndGroup

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 alt of entry.alternatives) {
      console.log(`Alternative ingredient index: ${alt.index}`);
    }
  }
}