String literal to template literal

60 Views Asked by At

Is there a way to convert a string literal into a template literal in Javascript 2015?

For example, something like the opposite of String.raw, like this:

String.template('hello ${name}!')  // returns `hello ${name}!`

And if it doesn't exist, then why not? Off the bat I would assume it might be a precautionary measure to prevent injection attacks, but... there are definitely cases where the above would really be useful and has no such risk

0

There are 0 best solutions below