@tmlmt/cooklang-parser / isSectionActive
Function: isSectionActive()
isSectionActive(
section,variant?):boolean
Determines if a section is active (should be displayed or processed) for a given variant.
- Sections with no
variantsproperty are always active. - When no variant is selected (default), sections tagged
[*]are active, and sections tagged with named variants are not. - When a named variant is selected, sections whose
variantsarray includes that name are active.
Parameters
section
The Section to check
variant?
string
The active variant name, or undefined/* for the default variant
Returns
boolean
true if the section should be displayed
Example
typescript
const recipe = new Recipe(cooklangText);
for (const section of recipe.sections) {
if (isSectionActive(section, choices.variant)) {
// render section
}
}