zspecza / common-tags

🔖 Useful template literal tags for dealing with strings in ES2015+

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Efficient way of eplacing a string in an external javascript file?

Extarys opened this issue · comments

Let me start by saying this project looks awesome.

I need to replace a string inside a javascript file before sending it from a server.

var file = 'var test = ${var}' // or fs.createReadStream('my.js', 'utf8')

reply
      .header('Content-Type', 'application/javascript; charset=UTF-8')
      // replace placeholder in js file
      .send(file)

Would this be possible with this package? 😄

Thanks!

Hi, for this String.replace would be most appropriate, but this package exports a tag called replaceStringTransformer that could solve your problem.