'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.likes === 0 && rating.dislikes === 0) || rating.stars === 0) { return '\x1b[90mUnrated\x1b[0m'; } if (rating.likes !== undefined && rating.dislikes === undefined) { return `\x1b[93m★\x1b[0m N/A \x1b[92m▲\x1b[0m ${String(rating.likes).padEnd(3)}`; } if (rating.stars) { return `\x1b[93m★ ${rating.stars.toFixed(2)}\x1b[0m`; } 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)}`; }, }; module.exports = formatters;