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

@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 variants property 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 variants array includes that name are active.

Parameters

section

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
  }
}