Let me explain my actual problem. I have a template string which could look like this:
/${name}
get
post
/{id}
get
/file-content
get
post
The indentation has to remain untouched.
Now if I were to use such a template string it might look like this:
function test(arr) {
let ret = []
arr.forEach(
function(name) {
return `/${name}
get
post
/{id}
get
/file-content
get
post`
return ret
}
)
}
Looks pretty ridiculous, right? I could of course put extra spaces into my template to match my code indentation, but then I'd have to perform unnecessary operations on the string afterwards to normalize it again.
So my idea was to move the template string to an external file and require
that file whenever I need the template string.
But require can't be used for that problem because it's nothing more than a text file and I certainly don't want to read that file from disk every time I need it and perform an eval
on it.
I could think of several workarounds for this problem, but I just cannot seem find a satisfying solution.