Skip to content

@xtandard/flags/evaluator

The flag evaluator — the heart of the runtime. Pure, synchronous, zero deps.

Implements the evaluation order from the spec:

  1. Flag disabled → default variant value (reason DISABLED)
  2. Prerequisites unmet → default variant value (reason PREREQUISITE_FAILED)
  3. Exact overrides → match on bucketing key (reason STATIC)
  4. Targeting rules → first matching rule wins (reason TARGETING_MATCH / SPLIT)
  5. Fallthrough → fixed variant or deterministic split (reason STATIC / SPLIT)
  6. Invalid config → no value (reason ERROR)

Prerequisites re-evaluate other flags from a passed-in flag map; the dependency graph is validated acyclic at publish time.

“Flag missing” (reason FLAG_NOT_FOUND) is handled one level up by the provider, which holds the caller’s default value.

import { … } from "@xtandard/flags/evaluator";
Name Summary
compareSemver Compare two semver strings. Returns -1, 0, 1, or undefined if either is invalid.
evaluateCondition Evaluate a single condition operator against a context attribute value.
evaluateFlag Evaluate a flag against an evaluation context.
evaluateNode Evaluate a single ConditionNode — a leaf condition or an AND/OR/NOT group — recursively. Groups: all → every child (AND), any → some child (OR), not → negation. An empty all matches; an empty any does not.
matchesRule All top-level nodes must pass (logical AND). An empty list always matches. Each node may itself be a nested AND/OR/NOT group (see evaluateNode).
pickVariant Deterministically choose a variant from a weighted split.
resolveBucketingKey Resolve the bucketing key for splits from the evaluation context.
Name Summary
FlagEvaluation The outcome of evaluating a single flag. value is undefined only on ERROR.
SplitInput Input to pickVariant.
Name Summary
SegmentMap Resolved segments embedded in a snapshot, keyed by segment key.