-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
46 lines (41 loc) · 1.21 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
46
/**
* CLI Alerts.
*
* Cross platform CLI Alerts with colors.
* Works on macOS, Linux, and Windows.
* Alerts: `success`, `info`, `warning`, `error`.
*
* @author Awais <https://twitter.com/MrAhmadAwais/>
*/
import chalk from "chalk";
import sym from "log-symbols";
const green = chalk.green;
const greenI = chalk.green.inverse;
const red = chalk.red;
const redI = chalk.red.bold.inverse;
const orange = chalk.keyword('orange');
const orangeI = chalk.keyword('orange').inverse;
const blue = chalk.blue;
const blueI = chalk.blue.inverse;
export default options => {
const defaultOptions = {
type: `error`,
msg: `You forgot to define all options.`,
name: ``
};
const opts = {...defaultOptions, ...options};
const {type, msg, name} = opts;
const printName = name ? name : type.toUpperCase();
if (type === `success`) {
console.log(`\n${sym.success} ${greenI(` ${printName} `)} ${green(msg)}\n`);
}
if (type === `warning`) {
console.log(`\n${sym.warning} ${orangeI(` ${printName} `)} ${orange(msg)}\n`);
}
if (type === `info`) {
console.log(`\n${sym.info} ${blueI(` ${printName} `)} ${blue(msg)}\n`);
}
if (type === `error`) {
console.log(`\n${sym.error} ${redI(` ${printName} `)} ${red(msg)}\n`);
}
};