-
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathLogging.ts
More file actions
47 lines (38 loc) · 1009 Bytes
/
Logging.ts
File metadata and controls
47 lines (38 loc) · 1009 Bytes
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
import pc from 'picocolors';
export function prepareMessage(msg: unknown): string {
if (typeof msg === 'string') {
return msg;
}
if (msg instanceof Error) {
return `${msg.stack || ''}`;
}
return JSON.stringify(msg, null, '\t');
}
export function l(msg: string): void {
// eslint-disable-next-line no-console
console.log(msg);
}
export function nl(): void {
return l('');
}
export function green(msg: string): void {
return l(pc.green(prepareMessage(msg)));
}
export function red(msg: string): void {
return l(pc.red(prepareMessage(msg)));
}
export function dim(msg: string): void {
return l(pc.dim(prepareMessage(msg)));
}
export function yellow(msg: string): void {
return l(pc.yellow(prepareMessage(msg)));
}
export function cyan(msg: string): void {
return l(pc.cyan(prepareMessage(msg)));
}
/**
* @deprecated Use `debug` from `src/utils/debug.ts` instead.
*/
export function debug(msg: unknown): void {
return l(pc.italic(pc.yellow(prepareMessage(msg))));
}