我已阅读Typescript中的template strings。我想知道我是否可以使用它们的时候,我从这样的文件中读取的字符串:字符串内插字符串从文件中读取字符串
let xmlPayloadTemplate = fs.readFileSync('payload.xml', 'utf8');
如果xmlPayloadTemplate
包含像${placeholder}
一个占位符,在那里进行一个内置的方式替代,以便我可以这样做:
let variableMap = {'placeholder' : 'value' }
xmlPayloadTemplate.interpolate(variableMap)
?
我知道a similar question about string interpolation in Javascript,但我想知道是否有更好的方法在Typescript中做到这一点。
感谢您的链接,我发现Lodash提供,我可以用一个模板函数。我会解决的! – reinouts
@reinouts很酷,确实使用它。 –