Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Execute the script
const script = new vm.Script(`result = ${func.toString()}(${argStr});`);
script.runInContext(sandbox, { timeout: 250 });
returnVal = sandbox.result;
}
}
catch (err) {
returnVal = null;
console.warn(`An error occured within custom function for ${componentKey}`, err);
}
}
else if (typeof func === 'object') {
try {
returnVal = jsonLogic.apply(func, args);
}
catch (err) {
returnVal = null;
console.warn(`An error occured within custom function for ${componentKey}`, err);
}
}
else if (func) {
console.warn(`Unknown function type for ${componentKey}`);
}
return returnVal;
}
export function checkJsonConditional(component, json, row, data, form, onError) {
try {
return jsonLogic.apply(json, {
data,
row,
form,
_,
});
}
catch (err) {
console.warn(`An error occurred in jsonLogic advanced condition for ${component.key}`, err);
return onError;
}
}
export const applyJsonLogic = (rule: any, state: any) => {
return jsonLogic.apply(rule, state);
};
function shouldRender(condition, properties, key) {
if (condition === undefined) {
return true;
}
const runtimeCondition = resolveArrayNotation(condition, key);
return jsonLogic.apply(runtimeCondition, properties);
}