UNPKG

465 BJavaScriptView Raw
1// Following is adapted from Vue CLI v2 "init" command
2
3const chalk = require('chalk')
4
5/**
6 * Evaluate an expression in meta.json in the context of
7 * prompt answers data.
8 */
9
10module.exports = function evaluate (exp, data) {
11 /* eslint-disable no-new-func */
12 const fn = new Function('data', 'with (data) { return ' + exp + '}')
13
14 try {
15 return fn(data)
16 }
17 catch (e) {
18 console.error(chalk.red('Error when evaluating filter condition: ' + exp))
19 }
20}