UNPKG

@discipl/law-reg

Version:

Discipl Law and Regulation Compliance Library

51 lines (43 loc) 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContextExplainer = void 0; class ContextExplainer { /** * Extend context with explanation * @param {Context} context * @return {Context} */ extendContextWithExplanation(context) { if (context.explanation) { const newExplanation = {}; if (Array.isArray(context.explanation.operandExplanations)) { context.explanation.operandExplanations.push(newExplanation); } else { context.explanation.operandExplanations = [newExplanation]; } return { ...context, explanation: newExplanation }; } else { return context; } } /** * Extend context explanation with result * @param {Context} context * @param {*} result * @return {Explanation} */ extendContextExplanationWithResult(context, result) { if (context.explanation && context.explanation.value == null) { if (typeof result === 'object') { context.explanation.value = String(result); } else { context.explanation.value = result; } } } } exports.ContextExplainer = ContextExplainer;