This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var stringify = function(obj, prop) { | |
var placeholder = '____PLACEHOLDER____'; | |
var fns = []; | |
var json = JSON.stringify(obj, function(key, value) { | |
if (typeof value === 'function') { | |
fns.push(value); | |
return placeholder; | |
} | |
return value; | |
}, 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function evaluate(code, args = {}) { | |
// Call is used to define where "this" within the evaluated code should reference. | |
// eval does not accept the likes of eval.call(...) or eval.apply(...) and cannot | |
// be an arrow function | |
return function evaluateEval() { | |
// Create an args definition list e.g. "arg1 = this.arg1, arg2 = this.arg2" | |
const argsStr = Object.keys(args) | |
.map(key => `${key} = this.${key}`) | |
.join(','); | |
const argsDef = argsStr ? `let ${argsStr};` : ''; |