Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Eval template strings
const regex = /(`[${}\w\.]+`)/gm
const evalInContext = function(input) {
const that = this
return input.replace(regex, function(match) {
return function() {
return eval(match)
}.call(that)
})
}
// evalInContext.call(data, template)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment