-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (40 loc) · 1.22 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
/**
* Cli Alerts.
*
* Cross platform CLI Alerts with colors & colored symbols for success, info, warning, error. Work on macOS, Linux, and Windows.
*
*
*/
const chalk = require("chalk");
const sym = require("log-symbols");
const log = console.log;
const green = chalk.green;
const greenI = chalk.green.bold.inverse;
const orange = chalk.keyword("orange");
const orangeI = chalk.keyword("orange").bold.inverse;
const red = chalk.red;
const redI = chalk.red.bold.inverse;
const blue = chalk.blue;
const blueI = chalk.blue.bold.inverse;
module.exports = options => {
const defaultOptions = {
type: `error`,
msg: `You forgot to define Options`,
name: null
};
const opt = { ...defaultOptions, ...options };
const { type, msg, name } = opt;
const printName = name ? name.toUpperCase() : type.toUpperCase();
if (type === "success") {
log(`\n${sym.success} ${greenI(` ${printName} `)} ${green(msg)}\n`);
}
if (type === "warning") {
log(`\n${sym.warning} ${orangeI(` ${printName} `)} ${orange(msg)}\n`);
}
if (type === "error") {
log(`\n${sym.error} ${redI(` ${printName} `)} ${red(msg)}\n`);
}
if (type === "info") {
log(`\n${sym.info} ${blueI(` ${printName} `)} ${blue(msg)}\n`);
}
};