Created
October 4, 2018 06:28
-
-
Save mediafreakch/6df34c440b7a6049aa34079b5c88b975 to your computer and use it in GitHub Desktop.
Eval template strings
This file contains hidden or 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
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