harvest-overtime
Version:
Track the overtime!
48 lines (47 loc) • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toTable = exports.toInfo = exports.toError = void 0;
const chalk = require("chalk");
const Table = require("cli-table3");
const bold = chalk.bold;
const errorColor = chalk.bold.red;
const infoColor = chalk.bold.blue;
const reset = chalk.reset;
const titleColor = chalk.bold.bgRedBright;
const TITLE = `${titleColor("harvest-overtime")} ⏰`;
function toError(args, error) {
const msg = `It was not possible to process ${infoColor(args.inputPath)}`;
return `${TITLE}\n\n${msg}\n${errorColor(error.message)}\n`;
}
exports.toError = toError;
function toInfo(args) {
const hours = `${bold("Regular day hours:")} ${infoColor(String(args.regularDayHours))}`;
const input = `${bold("Input file:")} ${infoColor(args.inputPath)}`;
const output = `${bold("Output file:")} ${infoColor(args.outputPath)}`;
return `${TITLE}\n\n${hours}\n${input}\n${output}\n`;
}
exports.toInfo = toInfo;
function toTable(reportEmployee) {
const table = new Table({
head: ["Employee", "Weekdays", "Weekends"],
});
const body = reportEmployee.map(({ report, employee }) => {
return [employee, setHour(report.weekdays), setHour(report.weekends)];
});
table.push(...body);
return table.toString();
}
exports.toTable = toTable;
function setHour(value) {
const color = setColor(value);
if (Number.isInteger(value)) {
return color(value.toString());
}
return color(value.toFixed(4));
}
function setColor(value) {
if (value > 0) {
return errorColor;
}
return reset;
}