-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstylish-log.js
48 lines (40 loc) · 960 Bytes
/
stylish-log.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
/*!
* Stylish-log
* @copyright João Victor Santos | jotavejv <[email protected]>
* @license MIT
*/
'use strict';
const styles = {
default: 'color: gray; font-weight: bold;',
info: 'color: blue; font-weight: bold;',
warn: 'color: #ffc107;',
danger: 'color: lightcoral; font-weight: bold;'
}
const logg = console.log;
function print(style, texts) {
let bindArgs = [console];
for (let text of texts) {
if (typeof text === "string" && bindArgs.length === 1) {
bindArgs.push('%c ' + text, style);
} else {
bindArgs.push(text);
}
}
return logg.bind(...bindArgs);
}
let log = {
styles,
show (...texts) {
return print(styles.default, texts);
},
info (...texts) {
return print(styles.info, texts);
},
warn (...texts) {
return print(styles.warn, texts);
},
danger (...texts) {
return print(styles.danger, texts);
}
};
module.exports = stylishLog;