Files
bower/lib/renderers/json.js
André Cruz 086fda5f24 CS.
2013-05-23 20:06:51 +01:00

40 lines
727 B
JavaScript

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;