npm.io
0.1.0 • Published 8 years ago

escape-template-string

Licence
MIT
Version
0.1.0
Deps
0
Size
846 B
Vulns
0
Weekly
0
Stars
1

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}\`;
// })`