traxxx/src/tui/formatters.js

27 lines
792 B
JavaScript
Raw Normal View History

'use strict';
const moment = require('moment');
const formatters = {
site: site => site.name,
date: (date, column) => moment(date).format(column.format || 'MMM DD, YYYY'),
actors: actors => actors.join(', '),
rating: (rating) => {
if (rating === null) {
return '\x1b[90mNot available\x1b[0m';
}
if (rating.stars === null) {
return '\x1b[90mUnrated\x1b[0m';
}
if (rating.likes === null || rating.dislikes === null) {
return `\x1b[93m★ ${rating.stars.toFixed(2)}\x1b[0m`;
}
return `\x1b[93m★\x1b[0m ${rating.stars.toFixed(2)} \x1b[92m▲\x1b[0m ${String(rating.likes).padEnd(3)} \x1b[31m▼\x1b[0m ${String(rating.dislikes).padEnd(3)}`;
},
};
module.exports = formatters;