-
Notifications
You must be signed in to change notification settings - Fork 0
/
devtools.js
executable file
·192 lines (170 loc) · 4.33 KB
/
devtools.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env node
import chalk from "chalk";
import inquirer from "inquirer";
import figlet from "figlet";
import { createSpinner } from "nanospinner";
import chalkAnimation from "chalk-animation";
// DEVTOOLS LOADING MENU SCREEN
figlet("DEVTOOLS", function (err, data) {
console.clear();
if (err) {
console.log("Could not load 'DEVTOOLS' ASCII art...");
}
const loadingMenuScreen = chalkAnimation.rainbow(data);
loadingMenuScreen.start();
setTimeout(() => {
loadingMenuScreen.stop();
devToolsMenu();
}, 2000);
});
// DEVTOOLS MENU
async function devToolsMenu() {
console.clear();
const answers = await inquirer.prompt({
name: "chosenTool",
type: "list",
message: "WELCOME TO DEVTOOLS! SELECT A TOOL TO USE:",
choices: [
"Random Color Generator",
"Decimal-to-Binary Converter",
"Countdown Timer",
"Digital Clock",
],
});
let chosenOption = answers.chosenTool;
switch (chosenOption) {
case "Random Color Generator":
runRandomColorGenerator();
break;
case "Decimal-to-Binary Converter":
runDecimalToBinaryConverter();
break;
case "Countdown Timer":
runCountdownTimer();
break;
case "Digital Clock":
runDigitalClock();
break;
}
}
// RANDOM COLOR GENERATOR TOOL
function runRandomColorGenerator() {
console.clear();
let rgbCodes = [];
let randomColorCode;
for (let i = 0; i < 3; i++) {
randomColorCode = Math.floor(Math.random() * 256);
rgbCodes.push(randomColorCode);
}
console.log(
chalk
.rgb(rgbCodes[0], rgbCodes[1], rgbCodes[2])
.bold(`${rgbCodes[0]}, ${rgbCodes[1]}, ${rgbCodes[2]}`)
);
anotherColorQuestion();
}
async function anotherColorQuestion() {
const answers = await inquirer.prompt({
name: "anotherColor",
type: "confirm",
message: "Generate another random color?",
});
if (answers.anotherColor) {
runRandomColorGenerator();
} else {
devToolsMenu();
}
}
// DECIMAL-TO-BINARY CONVERTER TOOL
async function runDecimalToBinaryConverter() {
console.clear();
const answers = await inquirer.prompt({
name: "enteredDecimal",
type: "number",
message: "Enter a decimal to convert to binary:",
validate: (answer) => {
if (isNaN(answer)) {
return `Invalid number. Press ${chalk
.rgb(255, 255, 255)
.bold("control + K")} and try again.`;
}
return true;
},
});
let decimalAsBinary = answers.enteredDecimal.toString(2);
console.log(chalk.rgb(119, 221, 119).bold(decimalAsBinary));
anotherDecimalQuestion();
}
async function anotherDecimalQuestion() {
const answers = await inquirer.prompt({
name: "anotherDecimal",
type: "confirm",
message: "Enter another decimal?",
});
if (answers.anotherDecimal) {
runDecimalToBinaryConverter();
} else {
devToolsMenu();
}
}
// COUNTDOWN TIMER TOOL
async function runCountdownTimer() {
console.clear();
const answers = await inquirer.prompt({
name: "timerDuration",
type: "number",
message: "Set a countdown timer for how many seconds?",
validate: (answer) => {
if (isNaN(answer)) {
return `Invalid number. Press ${chalk
.rgb(255, 255, 255)
.bold("control + K")} and try again.`;
}
return true;
},
});
let seconds = answers.timerDuration;
console.clear();
console.log(seconds);
let timer = setInterval(() => {
console.clear();
seconds--;
console.log(seconds);
if (seconds == 0) {
console.clear();
clearInterval(timer);
figlet("TIME!", function (err, data) {
if (err) {
console.log("Could not load 'TIME!' ASCII art...");
}
console.log(chalk.redBright.bold(data));
});
}
}, 1000);
}
// DIGITAL CLOCK TOOL
function runDigitalClock() {
console.clear();
const spinner = createSpinner("Loading...").start();
setInterval(() => {
spinner.stop();
let d = new Date();
let hour = d.getHours();
let minute = d.getMinutes();
let second = d.getSeconds();
let abbr = "AM";
if (hour >= 12) {
abbr = "PM";
}
if (minute < 10) {
minute = `0${minute}`;
}
if (second < 10) {
second = `0${second}`;
}
console.clear();
console.log(
chalk.rgb(255, 255, 255).bold(`${hour}:${minute}:${second} ${abbr}`)
);
}, 1000);
}