forked from OSSPhilippines/covid19-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateOutput.ts
More file actions
55 lines (47 loc) · 1.71 KB
/
generateOutput.ts
File metadata and controls
55 lines (47 loc) · 1.71 KB
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
import { generateColorTable } from "./generateTable";
import { getTimestamp } from "./getTimestamp";
import { getSaying } from "./getSaying";
import { lines } from "./getResponses";
/**
*
* @param chartType The type of chart that will be placed on the header
* @param updateTime The unix timestamp from the API of when the data was last updated
* @param data The data formatted into tables
* @param quiet Optional, set to true if the user does not want unnecessary information
* @returns A string containing a formatted table
*/
export const generateOutput: (
chartType: string,
updateTime: number,
data: (string | string[])[],
quiet?: boolean
) => string = (chartType, updateTime, data, quiet) => {
quiet = quiet === undefined ? true : quiet;
let header = `${lines.defaultHeader} - ${chartType}`;
let timestamp = getTimestamp(updateTime).yellow;
data.unshift(timestamp);
if (!quiet) data.unshift(header);
if (!quiet)
data = data.concat([
lines.helpMessage,
lines.docsLink,
lines.WNrepoLink,
]);
let response = generateColorTable(data, "cyan");
if (!quiet) {
response += `\n${getSaying().green}\n`; //saying
response += `\n${"═".repeat(60)}\n`;
}
response += lines.sponsorMessage; // support msg
// @ts-expect-error: Missing type definitions causes TS to highlight brightRed
response += `${lines.BMCLink}\n`.brightRed; //BMC link
if (!quiet) {
response += `${"═".repeat(60)}\n`;
response += `${lines.twitterPlug}`;
response +=
lines.handleHashtag.map((text) => text.black.bgCyan).join(" ") +
"\n";
}
response += "\n";
return response;
};