@xtandard/flags/evaluator
The flag evaluator — the heart of the runtime. Pure, synchronous, zero deps.
Implements the evaluation order from the spec:
- Flag disabled → default variant value (reason
DISABLED) - Prerequisites unmet → default variant value (reason
PREREQUISITE_FAILED) - Exact overrides → match on bucketing key (reason
STATIC) - Targeting rules → first matching rule wins (reason
TARGETING_MATCH/SPLIT) - Fallthrough → fixed variant or deterministic split (reason
STATIC/SPLIT) - 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";Functions
Section titled “Functions”| 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. |
Interfaces
Section titled “Interfaces”| Name | Summary |
|---|---|
FlagEvaluation |
The outcome of evaluating a single flag. value is undefined only on ERROR. |
SplitInput |
Input to pickVariant. |
Type aliases
Section titled “Type aliases”| Name | Summary |
|---|---|
SegmentMap |
Resolved segments embedded in a snapshot, keyed by segment key. |