String interpolation on variable
With something as simple as ${str} you can use a simple string replacement: var template = (tpl, args) => tpl.replace(/\${(\w+)}/g, (_, v) => args[v]); var tpl=”Hello ${str} and ${other}”; console.log(template(tpl, {str: ‘foo’, other: ‘bar’})); In a general case, no, not possible without eval (short of writing your own js interpreter), because ${…} can contain arbitrary … Read more