scraper/src/console/output.js

38 lines
525 B
JavaScript
Raw Normal View History

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