-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (36 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
const chalk = require("chalk");
const moment = require("moment");
const data = require("./data.json");
const getItem = () => {
let foundItem = undefined;
const now = moment(new Date());
data.sekki.forEach((sekki, index) => {
if (foundItem) return;
const current = moment(convertDate(sekki.startDate));
if (data.sekki[index + 1] === undefined) {
foundItem = sekki;
} else {
const next = moment(convertDate(data.sekki[index + 1].startDate));
if (now.isBetween(current, next)) {
foundItem = sekki;
}
}
});
return foundItem;
};
const convertDate = (value) => `${new Date().getFullYear()}-${value}`;
const run = () => {
const item = getItem();
console.log(`
${chalk("Twenty-four Sekki")}
${chalk.bold.gray("SEASON")} ${chalk(item.season)}
${chalk.bold.gray("NAME")} ${chalk(item.romanji)} (${chalk(item.kanji)})
${chalk.bold.gray("MEANING")} ${chalk(item.title)}
${chalk.bold.gray("ASSOCIATIONS")} ${chalk(item.description)}
${chalk.bold.gray("APPROX. DATE")} ${chalk(
moment(convertDate(item.startDate)).format("MMM Do")
)}
`);
};
run();