Skip to content

evaluateFlag

function evaluateFlag(
flag,
context,
allFlags?,
segments?,
now?
): FlagEvaluation;

Defined in: evaluator.ts:557

Evaluate a flag against an evaluation context.

Parameter Type
flag Flag
context EvaluationContext
allFlags? Record<string, Flag>
segments? SegmentMap
now? number

FlagEvaluation

A FlagEvaluation. value is undefined only when the flag config is invalid (reason ERROR); the provider substitutes the caller’s default in that case.

import { evaluateFlag } from "@xtandard/flags";
const flag = {
key: "new-onboarding",
type: "boolean" as const,
enabled: true,
defaultVariant: "off",
variants: { on: { value: true }, off: { value: false } },
fallthrough: { variant: "off" },
};
const { value, variant, reason } = evaluateFlag(flag, { targetingKey: "user-1" });
// value: false, variant: "off", reason: "STATIC"