Initial take on the commands + renderers + cli.

This commit is contained in:
André Cruz
2013-05-23 19:55:59 +01:00
parent 9f6bf62efc
commit cfb3d14028
21 changed files with 442 additions and 68 deletions

38
lib/renderers/json.js Normal file
View File

@@ -0,0 +1,38 @@
var circularJson = require('circular-json');
function renderHead() {
return '[';
}
function renderTail() {
return ']\n';
}
function renderData(data) {
return stringify(data) + ', ';
}
function renderError(err) {
return stringify(err) + ', ';
}
function renderEnd(data) {
return data ? stringify(data) : '';
}
// -------------------------
function uncolor(str) {
return str.replace(/\x1B\[\d+m/g, '');
}
function stringify(data) {
return uncolor(circularJson.stringify(data, null, ' '));
}
module.exports.head = renderHead;
module.exports.tail = renderTail;
module.exports.data = renderData;
module.exports.error = renderError;
module.exports.end = renderEnd;