Skip to content

Instantly share code, notes, and snippets.

@mediafreakch
Created October 4, 2018 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mediafreakch/6df34c440b7a6049aa34079b5c88b975 to your computer and use it in GitHub Desktop.
Save mediafreakch/6df34c440b7a6049aa34079b5c88b975 to your computer and use it in GitHub Desktop.
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