Created
March 21, 2017 11:03
-
-
Save malko/b8a432bbb2198ca5d38cd3dc27d40f24 to your computer and use it in GitHub Desktop.
dynamic es6 template string to template methods
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 tpl = makeTemplate('hello ${name}') | |
//const name = 'world'; | |
//tpl({name}); | |
const makeTemplate = (templateString) => { | |
return (templateData) => new Function(`{${Object.keys(templateData).join(',')}}`, 'return `' + templateString + '`')(templateData); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment