/* eslint-disable @typescript-eslint/no-explicit-any */ import Interpreter from 'js-interpreter'; import { PluginContext } from '../types/PluginContext.js'; import { SqupContext } from '../types/SqupContext.js'; import { Render } from './Render.js'; export function EvaluateCondition( pluginContext: PluginContext, squpContext: SqupContext, condition: string, replacements: Record> = {} ): boolean { const renderedCondition = Render(condition, pluginContext, replacements); if (squpContext.allowInlineEval) { const value = eval(renderedCondition); const resultBool = Boolean(value); squpContext.log.debug(`EvaluateCondition using eval: ${JSON.stringify(renderedCondition)} returns ${value} as boolean: ${resultBool}`); return resultBool; } else { const myInterpreter = new Interpreter(renderedCondition); myInterpreter.run(); const resultBool = Boolean(myInterpreter.value); squpContext.log.debug(`EvaluateCondition using js-interpreter: ${JSON.stringify(renderedCondition)} returns ${myInterpreter.value} as boolean: ${resultBool}`); return resultBool; } }