@redocly/theme
Version:
Shared UI components lib
23 lines • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchCodeWalkthroughConditions = matchCodeWalkthroughConditions;
const utils_1 = require("../../core/utils");
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, utils_1.isObject)(when)
? Object.entries(when).every(([key, value]) => evaluateCondition(key, value))
: true;
const matchesUnless = (0, utils_1.isObject)(unless)
? Object.entries(unless).some(([key, value]) => evaluateCondition(key, value))
: false;
return matchesWhen && !matchesUnless;
}
//# sourceMappingURL=match-code-walkthrough-conditions.js.map