-
-
Save lilac/e5a2ccd05030008eaff4bb3328785f07 to your computer and use it in GitHub Desktop.
dynamic es6 template string to template methods
This file contains 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