Apply template string dynamically in JavaScript [duplicate]

I would like to apply a string as a template but dynamically.

I have a string, coming from a config file, with the same “format” as a template string. For instance 'Hello, ${name}!' And I’d like to evaluate it as a template string, but dynamically, controlling the values in scope. Something like:

const input  = 'Hello, ${name}!';
const result = applyTemplate(input, {name: 'world'});
// result is 'Hello, world!'

Surprisingly, I have not found any way to achieve this. Any idea?