UNPKG

hypertune

Version:

[Hypertune](https://www.hypertune.com/) is the most flexible platform for feature flags, A/B testing, analytics and app configuration. Built with full end-to-end type-safety, Git-style version control and local, synchronous, in-memory flag evaluation. Opt

38 lines (35 loc) 927 B
import { rootFieldName } from "../shared/constants"; import { ObjectValue, Value } from "../shared/types"; import merge from "./merge"; export default function getOverrideFromOverridesList( values: [flagPath: string, value: Value | null][] ): ObjectValue | null { if (values.length === 0) { return null; } const override = merge<ObjectValue>( {}, ...values.flatMap(([flagPath, value]) => { if (value === null) { return []; } const flagPathSteps = flagPath.split(".").reverse(); const flagName = flagPathSteps.pop()!; return [ { [flagName]: flagPathSteps.reduce( (current, step) => ({ [step]: current }), value ), }, ]; }) ); if (Object.keys(override).length === 0) { return null; } if (!(rootFieldName in override)) { return { [rootFieldName]: override }; } return override; }