-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (36 loc) · 1.08 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
import boxen from "boxen";
// Constants
import { AsciiFolder } from "./lib/constants/environment.js";
// Utils
import Logger from "./utils/logger.js";
import { getAsciiList, getPath, openFile } from "./utils/file.util.js";
function printMessage (message, character, margin = 12) {
Logger.print(boxen(message, {
padding: 0.7,
margin: { left: margin },
borderStyle: "round",
}));
Logger.print(" ".repeat(margin - 1) + "/");
Logger.print(character);
}
const charsay = async (message, ascii = "homer", margin = 12) => {
try {
if(!message) {
throw Error("No message provided");
}
const asciiList = getAsciiList();
const path = getPath(`${AsciiFolder}${ascii}`);
const asciiCharacter = await openFile(path);
const existAscii = asciiList.indexOf(ascii)
if(!asciiList){
throw Error("No ASCII files");
}
if(!ascii || !existAscii) {
throw Error("Character not found");
}
printMessage(message, asciiCharacter, margin);
} catch(error) {
Logger.error("Something went wrong\n", error);
}
};
export default charsay;