38 lines
678 B
JavaScript
38 lines
678 B
JavaScript
"use strict";
|
|
|
|
var Class = require('class.extend');
|
|
|
|
var Output = Class.extend('Output', {
|
|
/**
|
|
* Convert and print data to json.
|
|
*
|
|
* @param mixed data
|
|
*/
|
|
json: function(data, pretty) {
|
|
data = JSON.stringify(
|
|
data,
|
|
function(key, value) {
|
|
if (value === undefined) {
|
|
return null;
|
|
}
|
|
|
|
return value;
|
|
},
|
|
pretty ? 2 : null
|
|
);
|
|
|
|
return this.write(data);
|
|
},
|
|
|
|
/**
|
|
* Print data.
|
|
*
|
|
* @param mixed data
|
|
*/
|
|
write: function(data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
|
|
module.exports = Output;
|