Skip to content

Instantly share code, notes, and snippets.

@replete
Created November 22, 2015 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save replete/0e664e7060c3c348b16d to your computer and use it in GitHub Desktop.
Save replete/0e664e7060c3c348b16d to your computer and use it in GitHub Desktop.
Allows strings to be parsed as if they were ES6 `template string interpolations`.
// phil@replete.nu
// Method for rendering normal strings as if they were ES6 `template strings like ${this}`
String.prototype.toTemplate = function() { return this.replace(/(\$\{.*?\})/g, m => eval('`'+m+'`')) };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment