2019-03-11 03:19:36 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
|
|
|
const formatters = {
|
|
|
|
site: site => site.name,
|
2019-04-10 01:42:20 +00:00
|
|
|
network: network => network.name,
|
2019-03-11 03:19:36 +00:00
|
|
|
date: (date, column) => moment(date).format(column.format || 'MMM DD, YYYY'),
|
|
|
|
actors: actors => actors.join(', '),
|
|
|
|
rating: (rating) => {
|
2019-03-23 21:48:39 +00:00
|
|
|
if ((rating.likes === 0 && rating.dislikes === 0) || rating.stars === 0) {
|
2019-03-11 03:51:28 +00:00
|
|
|
return '\x1b[90mUnrated\x1b[0m';
|
2019-03-11 03:19:36 +00:00
|
|
|
}
|
|
|
|
|
2019-04-06 21:24:26 +00:00
|
|
|
if (rating.likes !== undefined && rating.dislikes === undefined) {
|
|
|
|
return `\x1b[93m★\x1b[0m N/A \x1b[92m▲\x1b[0m ${String(rating.likes).padEnd(3)}`;
|
|
|
|
}
|
|
|
|
|
2019-03-23 21:48:39 +00:00
|
|
|
if (rating.stars) {
|
2019-03-11 03:51:28 +00:00
|
|
|
return `\x1b[93m★ ${rating.stars.toFixed(2)}\x1b[0m`;
|
2019-03-11 03:19:36 +00:00
|
|
|
}
|
|
|
|
|
2019-03-23 21:48:39 +00:00
|
|
|
const stars = rating.likes || rating.dislikes ? Math.floor(((rating.likes * 5 + rating.dislikes) / (rating.likes + rating.dislikes)) * 100) / 100 : null;
|
|
|
|
|
|
|
|
return `\x1b[93m★\x1b[0m ${stars.toFixed(2)} \x1b[92m▲\x1b[0m ${String(rating.likes).padEnd(3)} \x1b[31m▼\x1b[0m ${String(rating.dislikes).padEnd(3)}`;
|
2019-03-11 03:19:36 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = formatters;
|