Created
December 4, 2024 20:51
-
-
Save zzzarius/afa6ce9586ef24196b128b25552f8ffc to your computer and use it in GitHub Desktop.
Interpolate string template js
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 interpolate = function(template, params) { | |
const names = Object.keys(params); | |
const vals = Object.values(params); | |
return new Function(...names, `return \`${template}\`;`)(...vals); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment