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