str2fn
Version:
Invokes functions in a lookup table from a string name
18 lines (13 loc) • 349 B
JavaScript
/* eslint-disable no-new-func */
const lookup = function(fnStr, data) {
return new Function('obj', `
with(obj) {
return ${fnStr};
}
`)(data);
};
const execute = function(callString, obj, context) {
const data = Object.assign({}, obj, context);
return lookup(callString, data);
};
module.exports = execute;