scraper/src/console/output.js

38 lines
631 B
JavaScript
Raw Normal View History

2020-04-11 22:18:23 +02:00
"use strict";
class Output {
/**
* Convert and print data to json.
*
* @param mixed data
*/
json(data, pretty) {
data = JSON.stringify(
data,
function(key, value) {
if (value === undefined) {
2020-04-14 16:32:56 +02:00
return null
2020-04-11 22:18:23 +02:00
}
2020-04-14 16:32:56 +02:00
return value
2020-04-11 22:18:23 +02:00
},
pretty ? 2 : null
);
2020-04-14 16:32:56 +02:00
return this.write(data)
2020-04-11 22:18:23 +02:00
}
/**
* Print data.
*
* @param mixed data
*/
write(data, level) {
level = level || 'log'
console[level](data)
}
}
module.exports = Output