/
index.js
44 lines (34 loc) · 925 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
var util = require('util');
var os = require('os');
var Twig = require('twig');
var through2 = require('through2');
// Attach chalk colors.
var chalkTwig = require('chalk-twig-filters');
module.exports = {};
module.exports.format = function stringStream(format, options) {
chalkTwig(Twig, options);
var template = Twig.twig({
data: format,
});
var processor = function(data, enc, cb) {
if (typeof data === 'object') {
data = template.render(data);
}
cb(null, data + os.EOL);
};
return through2.obj(processor);
};
module.exports.prettyPrint = function() {
var processor = function(data, enc, cb) {
var options = {
showHidden: true,
depth: null,
colors: true,
};
cb(null, util.inspect(data, options) + os.EOL);
};
return through2.obj(processor);
};
// Export the twig instance so that it can be extended.
module.exports.Twig = Twig;