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

@tmlmt/cooklang-parser / isStepActive

Function: isStepActive()

isStepActive(step, variant?): boolean

Determines if a step is active (should be displayed) for a given variant.

  • Steps with no variants property are always active.
  • When no variant is selected (default), steps tagged [*] are active, and steps tagged with named variants are not.
  • When a named variant is selected, steps whose variants array includes that name are active.

Parameters

step

Step

The Step to check

variant?

string

The active variant name, or undefined/* for the default variant

Returns

boolean

true if the step should be displayed

Example

typescript
for (const item of section.content) {
  if (item.type === 'step' && isStepActive(item, choices.variant)) {
    // render step
  }
}