javascript - Loading ES6 template string from file -


let me explain actual problem. have template string this:

/${name}     post   /{id}         /file-content             post 

the indentation has remain untouched.

now if use such template string might this:

function test(arr) {     let ret = []     arr.foreach(         function(name) {             return `/${name}     post   /{id}         /file-content             post`             return ret         }     ) } 

looks pretty ridiculous, right? of course put spaces template match code indentation, i'd have perform unnecessary operations on string afterwards normalize again.

so idea move template string external file , require file whenever need template string.
require can't used problem because it's nothing more text file , don't want read file disk every time need , perform eval on it.

i think of several workarounds problem, cannot seem find satisfying solution.

how this:

// template.js module.exports = name => ` /${name}     post   /{id}         /file-content             post `.trim()  // app.js const template = require('./template')('name'); 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -