UNPKG

405 BJavaScriptView Raw
1const chalk = require('chalk');
2
3/**
4 * Evaluate an expression in meta.json in the context of
5 * prompt answers data.
6 */
7
8module.exports = function evaluate(exp, data) {
9 /* eslint-disable no-new-func */
10 const fn = new Function('data', `with (data) { return ${exp}}`);
11 try {
12 return fn(data);
13 } catch (e) {
14 console.error(chalk.red(`Error when evaluating filter condition: ${exp}`));
15 }
16};