zspecza / common-tags

🔖 Useful template literal tags for dealing with strings in ES2015+
Other
1.99k stars 60 forks source link

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

Closed Extarys closed 5 years ago

Extarys commented 5 years ago

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? :smile:

Thanks!

fatfisz commented 5 years ago

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