cu-api
Version:
An api for CU Boulder students.
43 lines (42 loc) • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.calendar = void 0;
const moment = require("moment");
function calendar() {
const startOfMonth = moment().month(1).startOf('month');
const day = startOfMonth.clone();
console.log(day.day('Monday'));
const days = [];
const month = startOfMonth.format('MMM');
const times = [];
for (let i = 0; i < startOfMonth.daysInMonth(); i++) {
if (i < 7) {
days.push(day.format('dd'));
}
if (day.format('MMM') !== month) {
times.push(' ');
}
else {
times.push(`${i % 7 == 0 ? '\n ' : ''}${day.format('DD')}`);
}
day.add(1, 'day');
}
console.log(` ${days.join(' ')}`);
console.log(`${month} ${times.join(' ')}`);
}
exports.calendar = calendar;
function dayBox(title, body, { padding = 2 } = {}) {
const lines = body.split('\n');
const maxLength = [title, ...lines].reduce((prevMax, line) => {
const length = line.length;
return length > prevMax ? length : prevMax;
}, 0);
const total = 2 + 2 * padding + maxLength;
const separator = ''.padStart(total, '-');
console.log(separator);
lines.forEach((line) => {
console.log(`|${''.padStart(padding, ' ')}${line}${''.padEnd(maxLength - line.length + padding, ' ')}|`);
});
console.log(separator);
}
dayBox('Tuesday', 'Calculus 2 (MATH 2300-015)');