-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutput.ts
46 lines (35 loc) · 1.07 KB
/
output.ts
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 { colorError, colorSystem, colorVerbose, colorWarning } from './colors.js';
let showVerbose = false;
export function getVerbose() {
return showVerbose;
}
export function setVerbose(verbose: boolean) {
showVerbose = verbose;
}
export function output(text: string, ...args: unknown[]) {
console.log(text, ...args);
}
export function outputSystem(text: string, ...args: unknown[]) {
console.log(colorSystem(text, ...args));
}
export function outputVerbose(message: string, ...args: unknown[]) {
if (showVerbose) {
console.log(colorVerbose(message, ...args));
}
}
export function outputWarning(text: string) {
console.warn(colorWarning(text));
}
export function outputError(error: unknown, ...args: unknown[]) {
const message = extractErrorMessage(error);
console.error(colorError(`ERROR: ${message}`, ...args));
}
export function extractErrorMessage(error: unknown) {
if (typeof error === 'object' && error != null && 'message' in error) {
return error.message;
}
if (typeof error === 'string') {
return error;
}
return 'Unknown error';
}