evaluateFlag
function evaluateFlag( flag, context, allFlags?, segments?, now?): FlagEvaluation;Defined in: evaluator.ts:557
Evaluate a flag against an evaluation context.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
flag |
Flag |
context |
EvaluationContext |
allFlags? |
Record<string, Flag> |
segments? |
SegmentMap |
now? |
number |
Returns
Section titled “Returns”A FlagEvaluation. value is undefined only when the flag
config is invalid (reason ERROR); the provider substitutes the caller’s
default in that case.
Example
Section titled “Example”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"