-
Notifications
You must be signed in to change notification settings - Fork 35
/
decorations.js
52 lines (43 loc) · 1.48 KB
/
decorations.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
import chalk from "chalk";
import Duration from "duration";
function formatDuration(start, end = new Date()) {
return new Duration(start, end).toString(1);
}
function getDurationStamp(start) {
const duration = formatDuration(start);
return chalk.grey(`${chalk.grey("[" + duration + "]")}`);
}
function getMessage(strings, values) {
return strings.reduce((result, string, index) => {
const value = typeof values[index] !== "undefined" ? values[index] : "";
const formatted =
value instanceof Date && index === values.length - 1
? getDurationStamp(value)
: value;
return `${result}${string}${formatted}`;
}, "");
}
export function fail(strings, ...values) {
const sign = `${chalk.red("✖")}`;
return `${sign} ${getMessage(strings, values)}`;
}
export function warn(strings, ...values) {
const sign = `${chalk.yellow("⚠")}`;
return `${sign} ${getMessage(strings, values)}`;
}
export function deprecation(strings, ...values) {
const sign = `${chalk.yellow("⚠ Deprecation")}`;
return `${sign} ${getMessage(strings, values)}`;
}
export function wait(strings, ...values) {
const sign = `${chalk.grey("⧗")}`;
return `${sign} ${getMessage(strings, values)}`;
}
export function ok(strings, ...values) {
const sign = `${chalk.grey("✔")}`;
return `${sign} ${getMessage(strings, values)}`;
}
export function ready(strings, ...values) {
const sign = `${chalk.green("✔")}`;
return `${sign} ${getMessage(strings, values)}`;
}