Reputation: 117
does anyone know if there is a node library that does this:
Example:
yaml:
properties:
instance_name: "myInstanceName"
instance_type: "myInstanceType"
template-string:
This is the instancename: ${properties.instance_name} and its type is ${properties.instance_type}
desired output:
This is the instancename: myInstanceName and its type is myInstanceType
Just wanted to ask if there is something out there to save my time :-)
Thanks guys!
Upvotes: 1
Views: 3576
Reputation: 117
This one helped me now:
https://www.npmjs.com/package/interpolate-json
https://www.npmjs.com/package/yaml
import * as YAML from 'yaml'
const { interpolation } = require('interpolate-json');
...
const cFile = fs.readFileSync('/config/cfg.yaml', 'utf-8')
const userData = fs.readFileSync('/config/uData.sh', 'utf-8')
const config = YAML.parse(configFile,{
prettyErrors:true
})
....
let interpolatedUserData = interpolation.expand(userData, config)
and viola....
Upvotes: 1