Parse in-string variables
npm install @tmware/variable-parser[Variable Parser] helps you translate in-string variables (i.e. {something} like this, where something would be a variable) to values.
With npm: npm install --save @tmware/variable-parser
With yarn: yarn add @tmware/variable-parser
``js
const VariableParser = require('@tmware/variable-parser')
const YourParser = new VariableParser() // initialize without data
`
`js`
const YourParser = new VariableParser({
testVariable: 'World',
anotherOne: 'Hello',
someNumber: 69
})
// initialize with data
`js`
console.log(
YourParser.parse(
'{anotherOne} {testVariable}! some text to show you that this works. {someNumber}'
)
)
// => 'Hello World! some text to show you that this works. 69'
Custom indicators (those things around the variables. default: {})
`js
const YourParser = new VariableParser({ someVariable: 3 }, '[]')
const result = YourParser.parse('[someVariable]')
console.log(result)
// => '3'
// Note: This is still a string
``
Please refer to the LICENSE file.
[variable parser]: https://github.com/TMWare/variable-parser