babelon
JSON templates using ES6+ object notation.
Like JSON, but really JS.
babelon
uses vm
, Function
, and/or eval
, so only use it where you trust the input.
Install
npm i --save babelon
Example
Let's say you want to mockup an JSON response, you can use babelon
to write a template:
> example.babelon
user: id: user_id /* variables */ name: ` ` // templates posts: posts { // functions let a = 1; return v+a; } ...misc // object spread properties is_active // property shorthand
> index.js
;; let tmpl = babelon; let obj = ; // obj:// { user: { id: 1, name: 'First Last' },// posts: [ { id: 1 } ],// addOne: [Function],// is_active: true }
Methods
-
babelon.compileFile(file_path)
: returns callable template -
babelon.evalFile(file_path, locals = null)
: returns rendered template using locals -
babelon.compile(code_str)
: returns callable template -
babelon.eval(code_str, locals = null)
: returns rendered template using locals