UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

55 lines 1.77 kB
"use strict"; /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ /** * @module botbuilder-dialogs-adaptive */ Object.defineProperty(exports, "__esModule", { value: true }); exports.evaluateExpression = exports.replaceJsonRecursively = void 0; const adaptive_expressions_1 = require("adaptive-expressions"); /** * Replaces the binding paths in a JSON value with the evaluated results recursively. * * @param state A scope for looking up variables. * @param unit An object. * @returns Deep data binding result. */ function replaceJsonRecursively(state, unit) { if (typeof unit === 'string') { const { value, error } = new adaptive_expressions_1.ValueExpression(unit).tryGetValue(state); if (!error) { return value; } return unit; } if (Array.isArray(unit)) { const result = []; for (const child of unit) { result.push(replaceJsonRecursively(state, child)); } return result; } if (typeof unit === 'object') { const result = {}; for (const key in unit) { result[key] = replaceJsonRecursively(state, unit[key]); } return result; } return unit; } exports.replaceJsonRecursively = replaceJsonRecursively; /** * Evaluate ValueExpression according the value type. * * @param state Input ValueExpression * @param valExpr A scope for looking up variables. * @returns Deep data binding result. */ function evaluateExpression(state, valExpr) { return valExpr.expressionText == null ? replaceJsonRecursively(state, valExpr.value) : valExpr.getValue(state); } exports.evaluateExpression = evaluateExpression; //# sourceMappingURL=jsonExtensions.js.map