this is a logicless json template engine
npm install @francomalatacca/eyebrows{: eyebrows - logicless basic templating system for JSON
===
eyebrows is a JSON oriented logicless template library used for replacement of placeholders within a json structure with actual data.
The basic functionality is to provide a base template with some placeholders and a flat data object.
eyebrows will replace any occurrence of the placeholders within the JSON template with actual data.
Install with npm:
``sh`
$ npm install --save @francomalatacca/eyebrows
template:
`javascript`
{
"key": "{{value}}"
}
data object:
`javascript`
{
"value": "hello world!"
}
to process the template and get the result
`javascript`
const eb = require('eyebrows');
const result = eb.render(template, dataObject);
template:
`javascript`
{
"{{?value}}": {
"key": "this key_value will show if value is true replacing the ?value key element"
}
}
data object:
`javascript`
{
"value": true
}
output:
`javascript`
{
"key": "this key_value will show if value is true replacing the ?value key element"
}
template:
`javascript`
{
"student": {
"name": "jack doe",
"{{..parents}}": {
"name": "{{name}}",
"other": false,
"age": "{{age}}",
}
}
}
data object:
`javascript`
{
"parents": [
{
"name": "jonh doe",
"age": 32
},
{
"name": "jane edo",
"age": 29
}
]
}
output:
`javascript`
{
"student": {
"name": "jack doe",
"parents": [
{
"name": "jonh doe",
"other": false,
"age": 32
},
{
"name": "jane edo",
"other": false,
"age": 29
}
]
}
and with objects
template:
`javascript`
{
"a": {
"b": {
"{{__elements}}": {
"first": {
"name": "{{name}}",
"age": "{{age}}"
},
"second": {
"name": "{{name}}",
"age": "{{age}}"
}
}
}
}
}
data object:
`javascript`
{
elements: {
"first": {
"name": "abc",
"lastName": "cde",
"age": 18
},
"second": {
"name": "xyz",
"lastName": "str",
"age": 29
}
}
}
output:
`javascript`
{
"a":{
"b":{
"elements":{
"first":{
"name":"abc",
"age":18
},
"second":{
"name":"xyz",
"age":29
}
}
}
}
}
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
`sh``
$ npm install && npm run test
Copyright © 2020, franco malatacca.
Released under the MIT License.