-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.js
More file actions
65 lines (61 loc) · 1.65 KB
/
example.js
File metadata and controls
65 lines (61 loc) · 1.65 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
var coolors = require('./coolors');
var msg = 'My cool console log';
/**
* SIMPLE
*/
console.log(coolors(msg, 'red'));
console.log(coolors(msg, 'bgBlue'));
var msgWordColors = msg.split(' ');
console.log(coolors(msgWordColors[0], 'green') + ' ' + coolors(msgWordColors[1], 'bgMagenta') + ' ' + coolors(msgWordColors[2], 'bold') + ' ' + coolors(msgWordColors[3], 'strikethrough'));
/**
* CONFIGURATION
*/
console.log(coolors(msg, {
text: 'yellow'
}));
console.log(coolors(msg, {
text: 'yellow',
background: 'blue'
}));
console.log(coolors(msg, {
text: 'yellow',
background: 'blue',
bold: true
}));
console.log(coolors(msg, {
text: 'yellow',
background: 'red',
bold: true,
underline: true,
inverse: true,
strikethrough: true
}));
/**
* EXTENDING
* (Stupids examples :D)
*/
function ligthRed(msg){
return '\u001b[91m' + msg + '\u001b[39m';
}
coolors.addPlugin('ligthRed', ligthRed);
console.log(coolors('New color', 'ligthRed'));
function rainbowLog(msg){
var colorsText = coolors.availableStyles().text;
var rainbowColors = colorsText.splice(3);
var lengthRainbowColors = rainbowColors.length;
var msgInLetters = msg.split('');
var rainbowEndText = '';
var i = 0;
msgInLetters.forEach(function(letter){
if(letter != ' '){
if(i === lengthRainbowColors) i = 0;
rainbowEndText += coolors(letter, rainbowColors[i]);
i++;
}else{
rainbowEndText += ' ';
}
});
return rainbowEndText;
}
coolors.addPlugin('rainbow', rainbowLog);
console.log(coolors('This its a creative example extending core with a cool rainbow style', 'rainbow'));