Consolidate-compatible API to use JSTransformers.
npm install consolidate-jstransformerConsolidate-compatible API to use JSTransformers.





Replace the consolidate package with consolidate-jstransformer.
`` javascript`
var cons = require('consolidate')
` javascript`
var cons = require('consolidate-jstransformer')
Use consolidate-jstransformer the same way you would use Consolidate:
`js`
var cons = require('consolidate-jstransformer');
cons.swig('views/page.html', { user: 'tobi' }, function(err, html){
if (err) throw err;
console.log(html);
});
Or without options / local variables:
`js`
var cons = require('consolidate-jstransformer');
cons.swig('views/page.html', function(err, html){
if (err) throw err;
console.log(html);
});
To dynamically pass the engine, simply use the subscript operator and a variable:
`js
var cons = require('consolidate-jstransformer')
, name = 'swig';
consname{
if (err) throw err;
console.log(html);
});
`
Render strings rather than files:
`js
var cons = require('consolidate-jstransformer')
, name = 'swig';
cons[name].render('Hello {{ user }}', { user: 'tobi' }, function(err, html){
if (err) throw err;
console.log(html);
});
`
If no callback function is provided, a Promise will be returned.
`js
var cons = require('consolidate-jstransformer');
cons.swig('views/page.html', { user: 'tobi' })
.then(function (html) {
console.log(html);
})
.catch(function (err) {
throw err;
});
``
MIT