UNPKG

465 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 console.log(exp,'exp');
13 console.log(data, 'data');
14 return fn(data)
15 } catch (e) {
16 console.error(chalk.red('Error when evaluating filter condition: ' + exp))
17 }
18}