rameshvarun / escape-template-string

Escape a string so that it can be eval-ed in as a template literal.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

escape-template-string

Node.js CI

Escape a string so that it can be eval-ed in as a template literal. This is useful for projects such as ProtoWorld that generate human-readable JavaScript code.

console.log(escape(`(function() {
  var x = 'test';
  return \`\${x}\\n\${x}\`;
})`));
// This prints the string below, which can be eval-ed in.
// `(function() {
//   var x = 'test';
//   return \`\${x}\\n\${x}\`;
// })`

About

Escape a string so that it can be eval-ed in as a template literal.

License:MIT License


Languages

Language:JavaScript 100.0%