-
-
Save dreadjr/eb9a7ba38575f348bd02b726e46a3cb0 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