jbj-template

JBJ template module: advanced use of variables within strings (compute, template)

Usage no npm install needed!

<script type="module">
  import jbjTemplate from 'https://cdn.skypack.dev/jbj-template';
</script>

README

JBJ template module

JBJ template module: advanced use of variables within strings (compute, template)

Contributors

Installation

$ npm install jbj-template

Usage

This JBJ module cannot be used alone. JBJ has to be installed.

var JBJ = require('jbj');
JBJ.use(require('jbj-template'));

Tests

Use mocha to run the tests.

$ npm install
$ npm test

Actions

Once the module is declared as used for JBJ, you can use the following actions:

template: mustacheTemplate | [mustacheTemplate, mustacheTemplate, ...]

Build a string with mustache template and input

    var stylesheet = {
        "set" : {
            "a" : {
                "b" : "hello"
            },
            "c" : "world"
        },
        "template": "I say {{a.b}} to the {{c}}"
    };
    // output : I say hello to the world

compute: expression

Compute an expression with all variables of the input. Use the filtrex syntax. Note : this variable contains input

    var stylesheet = {
        "set" : {
            "a" : 20,
            "b" : 3,
            "c" : 5,
            "d" : 8
        },
        "$x" : {
            "compute#1": "a / b",
            "compute#2": "round(this)",
            "cast": "number"
        },
        "$y" : {
            "path": "b",
            "cast": "number"
        },
        "$z" : {
            "compute": "x + y",
        }
    };
    // output : 10

Examples

See unit tests : https://github.com/Inist-CNRS/node-jbj-template/tree/master/test

Try it

http://Inist-CNRS.github.io/node-jbj/

License

MIT