1

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

risto
  • 1,274
  • 9
  • 11
  • A literal, by definition, isn't dynamically built. – Denys Séguret Apr 10 '16 at 13:43
  • Hmm, I've been searching for like a half hour and I couldn't find these other posts on the subject. Thanks for linking – risto Apr 10 '16 at 13:45
  • @axelpods mentions `eval` as a possibility [here](http://stackoverflow.com/questions/29182244/convert-a-string-to-a-template-string?lq=1), though it's a bit of a hack – risto Apr 10 '16 at 13:45
  • `assemble` from [here](http://stackoverflow.com/questions/29771597/how-can-i-construct-a-template-string-from-a-regular-string) seems better. – risto Apr 10 '16 at 13:52

0 Answers0