UNPKG

@redocly/theme

Version:

Shared UI components lib

23 lines 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.matchCodeWalkthroughConditions = matchCodeWalkthroughConditions; const type_guards_1 = require("./type-guards"); function matchCodeWalkthroughConditions(conditions = {}, state) { const { when, unless } = conditions; function evaluateCondition(key, value) { var _a; const stateValue = (_a = state[key]) === null || _a === void 0 ? void 0 : _a.value; if (Array.isArray(value) && typeof stateValue === 'string') { return value.includes(stateValue); } return stateValue === value; } const matchesWhen = (0, type_guards_1.isObject)(when) ? Object.entries(when).every(([key, value]) => evaluateCondition(key, value)) : true; const matchesUnless = (0, type_guards_1.isObject)(unless) ? Object.entries(unless).some(([key, value]) => evaluateCondition(key, value)) : false; return matchesWhen && !matchesUnless; } //# sourceMappingURL=match-code-walkthrough-conditions.js.map