colors 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/examples/normal-usage.js +26 -23
- package/examples/safe-string.js +23 -22
- package/lib/colors.js +47 -39
- package/lib/custom/trap.js +36 -35
- package/lib/custom/zalgo.js +30 -24
- package/lib/extendStringPrototype.js +36 -35
- package/lib/index.js +4 -3
- package/lib/maps/america.js +7 -7
- package/lib/maps/rainbow.js +5 -4
- package/lib/maps/random.js +8 -4
- package/lib/maps/zebra.js +2 -2
- package/lib/styles.js +3 -3
- package/lib/system/has-flag.js +23 -11
- package/lib/system/supports-colors.js +102 -98
- package/package.json +13 -4
- package/safe.js +2 -1
- package/themes/generic-logging.js +2 -2
package/examples/normal-usage.js
CHANGED
@@ -1,34 +1,36 @@
|
|
1
1
|
var colors = require('../lib/index');
|
2
2
|
|
3
|
-
console.log(
|
3
|
+
console.log('First some yellow text'.yellow);
|
4
4
|
|
5
|
-
console.log(
|
5
|
+
console.log('Underline that text'.yellow.underline);
|
6
6
|
|
7
|
-
console.log(
|
7
|
+
console.log('Make it bold and red'.red.bold);
|
8
8
|
|
9
|
-
console.log((
|
9
|
+
console.log(('Double Raindows All Day Long').rainbow);
|
10
10
|
|
11
|
-
console.log(
|
11
|
+
console.log('Drop the bass'.trap);
|
12
12
|
|
13
|
-
console.log(
|
13
|
+
console.log('DROP THE RAINBOW BASS'.trap.rainbow);
|
14
14
|
|
15
|
+
// styles not widely supported
|
16
|
+
console.log('Chains are also cool.'.bold.italic.underline.red);
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
console.log(
|
18
|
+
// styles not widely supported
|
19
|
+
console.log('So '.green + 'are'.underline + ' ' + 'inverse'.inverse
|
20
|
+
+ ' styles! '.yellow.bold);
|
21
|
+
console.log('Zebras are so fun!'.zebra);
|
20
22
|
|
21
23
|
//
|
22
24
|
// Remark: .strikethrough may not work with Mac OS Terminal App
|
23
25
|
//
|
24
|
-
console.log(
|
26
|
+
console.log('This is ' + 'not'.strikethrough + ' fun.');
|
25
27
|
|
26
|
-
console.log('Background color attack!'.black.bgWhite)
|
27
|
-
console.log('Use random styles on everything!'.random)
|
28
|
-
console.log('America, Heck Yeah!'.america)
|
28
|
+
console.log('Background color attack!'.black.bgWhite);
|
29
|
+
console.log('Use random styles on everything!'.random);
|
30
|
+
console.log('America, Heck Yeah!'.america);
|
29
31
|
|
30
32
|
|
31
|
-
console.log('Setting themes is useful')
|
33
|
+
console.log('Setting themes is useful');
|
32
34
|
|
33
35
|
//
|
34
36
|
// Custom themes
|
@@ -45,17 +47,17 @@ colors.setTheme({
|
|
45
47
|
help: 'cyan',
|
46
48
|
warn: 'yellow',
|
47
49
|
debug: 'blue',
|
48
|
-
error: 'red'
|
50
|
+
error: 'red',
|
49
51
|
});
|
50
52
|
|
51
53
|
// outputs red text
|
52
|
-
console.log(
|
54
|
+
console.log('this is an error'.error);
|
53
55
|
|
54
56
|
// outputs yellow text
|
55
|
-
console.log(
|
57
|
+
console.log('this is a warning'.warn);
|
56
58
|
|
57
59
|
// outputs grey text
|
58
|
-
console.log(
|
60
|
+
console.log('this is an input'.input);
|
59
61
|
|
60
62
|
console.log('Generic logging theme as file'.green.bold.underline);
|
61
63
|
|
@@ -67,12 +69,13 @@ try {
|
|
67
69
|
}
|
68
70
|
|
69
71
|
// outputs red text
|
70
|
-
console.log(
|
72
|
+
console.log('this is an error'.error);
|
71
73
|
|
72
74
|
// outputs yellow text
|
73
|
-
console.log(
|
75
|
+
console.log('this is a warning'.warn);
|
74
76
|
|
75
77
|
// outputs grey text
|
76
|
-
console.log(
|
78
|
+
console.log('this is an input'.input);
|
79
|
+
|
80
|
+
// console.log("Don't summon".zalgo)
|
77
81
|
|
78
|
-
//console.log("Don't summon".zalgo)
|
package/examples/safe-string.js
CHANGED
@@ -1,37 +1,39 @@
|
|
1
1
|
var colors = require('../safe');
|
2
2
|
|
3
|
-
console.log(colors.yellow(
|
3
|
+
console.log(colors.yellow('First some yellow text'));
|
4
4
|
|
5
|
-
console.log(colors.yellow.underline(
|
5
|
+
console.log(colors.yellow.underline('Underline that text'));
|
6
6
|
|
7
|
-
console.log(colors.red.bold(
|
7
|
+
console.log(colors.red.bold('Make it bold and red'));
|
8
8
|
|
9
|
-
console.log(colors.rainbow(
|
9
|
+
console.log(colors.rainbow('Double Raindows All Day Long'));
|
10
10
|
|
11
|
-
console.log(colors.trap(
|
11
|
+
console.log(colors.trap('Drop the bass'));
|
12
12
|
|
13
|
-
console.log(colors.rainbow(colors.trap(
|
13
|
+
console.log(colors.rainbow(colors.trap('DROP THE RAINBOW BASS')));
|
14
14
|
|
15
|
-
|
15
|
+
// styles not widely supported
|
16
|
+
console.log(colors.bold.italic.underline.red('Chains are also cool.'));
|
16
17
|
|
18
|
+
// styles not widely supported
|
19
|
+
console.log(colors.green('So ') + colors.underline('are') + ' '
|
20
|
+
+ colors.inverse('inverse') + colors.yellow.bold(' styles! '));
|
17
21
|
|
18
|
-
console.log(colors.
|
22
|
+
console.log(colors.zebra('Zebras are so fun!'));
|
19
23
|
|
20
|
-
console.log(colors.
|
21
|
-
|
22
|
-
console.log("This is " + colors.strikethrough("not") + " fun.");
|
24
|
+
console.log('This is ' + colors.strikethrough('not') + ' fun.');
|
23
25
|
|
24
26
|
|
25
27
|
console.log(colors.black.bgWhite('Background color attack!'));
|
26
|
-
console.log(colors.random('Use random styles on everything!'))
|
28
|
+
console.log(colors.random('Use random styles on everything!'));
|
27
29
|
console.log(colors.america('America, Heck Yeah!'));
|
28
30
|
|
29
|
-
console.log('Setting themes is useful')
|
31
|
+
console.log('Setting themes is useful');
|
30
32
|
|
31
33
|
//
|
32
34
|
// Custom themes
|
33
35
|
//
|
34
|
-
//console.log('Generic logging theme as JSON'.green.bold.underline);
|
36
|
+
// console.log('Generic logging theme as JSON'.green.bold.underline);
|
35
37
|
// Load theme with JSON literal
|
36
38
|
colors.setTheme({
|
37
39
|
silly: 'rainbow',
|
@@ -43,17 +45,17 @@ colors.setTheme({
|
|
43
45
|
help: 'cyan',
|
44
46
|
warn: 'yellow',
|
45
47
|
debug: 'blue',
|
46
|
-
error: 'red'
|
48
|
+
error: 'red',
|
47
49
|
});
|
48
50
|
|
49
51
|
// outputs red text
|
50
|
-
console.log(colors.error(
|
52
|
+
console.log(colors.error('this is an error'));
|
51
53
|
|
52
54
|
// outputs yellow text
|
53
|
-
console.log(colors.warn(
|
55
|
+
console.log(colors.warn('this is a warning'));
|
54
56
|
|
55
57
|
// outputs grey text
|
56
|
-
console.log(colors.input(
|
58
|
+
console.log(colors.input('this is an input'));
|
57
59
|
|
58
60
|
|
59
61
|
// console.log('Generic logging theme as file'.green.bold.underline);
|
@@ -62,15 +64,14 @@ console.log(colors.input("this is an input"));
|
|
62
64
|
colors.setTheme(__dirname + '/../themes/generic-logging.js');
|
63
65
|
|
64
66
|
// outputs red text
|
65
|
-
console.log(colors.error(
|
67
|
+
console.log(colors.error('this is an error'));
|
66
68
|
|
67
69
|
// outputs yellow text
|
68
|
-
console.log(colors.warn(
|
70
|
+
console.log(colors.warn('this is a warning'));
|
69
71
|
|
70
72
|
// outputs grey text
|
71
|
-
console.log(colors.input(
|
73
|
+
console.log(colors.input('this is an input'));
|
72
74
|
|
73
75
|
// console.log(colors.zalgo("Don't summon him"))
|
74
76
|
|
75
77
|
|
76
|
-
|
package/lib/colors.js
CHANGED
@@ -40,38 +40,38 @@ var newLineRegex = new RegExp(/[\r\n]+/g);
|
|
40
40
|
|
41
41
|
colors.supportsColor = require('./system/supports-colors').supportsColor;
|
42
42
|
|
43
|
-
if (typeof colors.enabled ===
|
43
|
+
if (typeof colors.enabled === 'undefined') {
|
44
44
|
colors.enabled = colors.supportsColor() !== false;
|
45
45
|
}
|
46
46
|
|
47
|
-
colors.enable = function
|
47
|
+
colors.enable = function() {
|
48
48
|
colors.enabled = true;
|
49
49
|
};
|
50
50
|
|
51
|
-
colors.disable = function
|
51
|
+
colors.disable = function() {
|
52
52
|
colors.enabled = false;
|
53
53
|
};
|
54
54
|
|
55
|
-
colors.stripColors = colors.strip = function(str){
|
56
|
-
return (
|
55
|
+
colors.stripColors = colors.strip = function(str) {
|
56
|
+
return ('' + str).replace(/\x1B\[\d+m/g, '');
|
57
57
|
};
|
58
58
|
|
59
|
-
|
60
|
-
var stylize = colors.stylize = function stylize
|
59
|
+
// eslint-disable-next-line no-unused-vars
|
60
|
+
var stylize = colors.stylize = function stylize(str, style) {
|
61
61
|
if (!colors.enabled) {
|
62
62
|
return str+'';
|
63
63
|
}
|
64
64
|
|
65
65
|
return ansiStyles[style].open + str + ansiStyles[style].close;
|
66
|
-
}
|
66
|
+
};
|
67
67
|
|
68
68
|
var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
|
69
|
-
var escapeStringRegexp = function
|
69
|
+
var escapeStringRegexp = function(str) {
|
70
70
|
if (typeof str !== 'string') {
|
71
71
|
throw new TypeError('Expected a string');
|
72
72
|
}
|
73
|
-
return str.replace(matchOperatorsRe,
|
74
|
-
}
|
73
|
+
return str.replace(matchOperatorsRe, '\\$&');
|
74
|
+
};
|
75
75
|
|
76
76
|
function build(_styles) {
|
77
77
|
var builder = function builder() {
|
@@ -84,15 +84,16 @@ function build(_styles) {
|
|
84
84
|
return builder;
|
85
85
|
}
|
86
86
|
|
87
|
-
var styles = (function
|
87
|
+
var styles = (function() {
|
88
88
|
var ret = {};
|
89
89
|
ansiStyles.grey = ansiStyles.gray;
|
90
|
-
Object.keys(ansiStyles).forEach(function
|
91
|
-
ansiStyles[key].closeRe =
|
90
|
+
Object.keys(ansiStyles).forEach(function(key) {
|
91
|
+
ansiStyles[key].closeRe =
|
92
|
+
new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
|
92
93
|
ret[key] = {
|
93
|
-
get: function
|
94
|
+
get: function() {
|
94
95
|
return build(this._styles.concat(key));
|
95
|
-
}
|
96
|
+
},
|
96
97
|
};
|
97
98
|
});
|
98
99
|
return ret;
|
@@ -104,7 +105,11 @@ function applyStyle() {
|
|
104
105
|
var args = Array.prototype.slice.call(arguments);
|
105
106
|
|
106
107
|
var str = args.map(function(arg) {
|
107
|
-
|
108
|
+
if (arg !== undefined && arg.constructor === String) {
|
109
|
+
return arg;
|
110
|
+
} else {
|
111
|
+
return util.inspect(arg);
|
112
|
+
}
|
108
113
|
}).join(' ');
|
109
114
|
|
110
115
|
if (!colors.enabled || !str) {
|
@@ -119,7 +124,7 @@ function applyStyle() {
|
|
119
124
|
while (i--) {
|
120
125
|
var code = ansiStyles[nestedStyles[i]];
|
121
126
|
str = code.open + str.replace(code.closeRe, code.open) + code.close;
|
122
|
-
if (newLinesPresent){
|
127
|
+
if (newLinesPresent) {
|
123
128
|
str = str.replace(newLineRegex, code.close + '\n' + code.open);
|
124
129
|
}
|
125
130
|
}
|
@@ -127,46 +132,49 @@ function applyStyle() {
|
|
127
132
|
return str;
|
128
133
|
}
|
129
134
|
|
130
|
-
colors.setTheme = function
|
135
|
+
colors.setTheme = function(theme) {
|
131
136
|
if (typeof theme === 'string') {
|
132
137
|
console.log('colors.setTheme now only accepts an object, not a string. ' +
|
133
|
-
'If you are trying to set a theme from a file, it is now your (the
|
134
|
-
'
|
135
|
-
'
|
138
|
+
'If you are trying to set a theme from a file, it is now your (the ' +
|
139
|
+
'caller\'s) responsibility to require the file. The old syntax ' +
|
140
|
+
'looked like colors.setTheme(__dirname + ' +
|
141
|
+
'\'/../themes/generic-logging.js\'); The new syntax looks like '+
|
142
|
+
'colors.setTheme(require(__dirname + ' +
|
143
|
+
'\'/../themes/generic-logging.js\'));');
|
136
144
|
return;
|
137
145
|
}
|
138
146
|
for (var style in theme) {
|
139
|
-
(function(style){
|
140
|
-
colors[style] = function(str){
|
141
|
-
if (typeof theme[style] === 'object'){
|
147
|
+
(function(style) {
|
148
|
+
colors[style] = function(str) {
|
149
|
+
if (typeof theme[style] === 'object') {
|
142
150
|
var out = str;
|
143
|
-
for (var i in theme[style]){
|
151
|
+
for (var i in theme[style]) {
|
144
152
|
out = colors[theme[style][i]](out);
|
145
153
|
}
|
146
154
|
return out;
|
147
155
|
}
|
148
156
|
return colors[theme[style]](str);
|
149
157
|
};
|
150
|
-
})(style)
|
158
|
+
})(style);
|
151
159
|
}
|
152
|
-
}
|
160
|
+
};
|
153
161
|
|
154
162
|
function init() {
|
155
163
|
var ret = {};
|
156
|
-
Object.keys(styles).forEach(function
|
164
|
+
Object.keys(styles).forEach(function(name) {
|
157
165
|
ret[name] = {
|
158
|
-
get: function
|
166
|
+
get: function() {
|
159
167
|
return build([name]);
|
160
|
-
}
|
168
|
+
},
|
161
169
|
};
|
162
170
|
});
|
163
171
|
return ret;
|
164
172
|
}
|
165
173
|
|
166
|
-
var sequencer = function sequencer
|
167
|
-
var exploded = str.split(
|
174
|
+
var sequencer = function sequencer(map, str) {
|
175
|
+
var exploded = str.split('');
|
168
176
|
exploded = exploded.map(map);
|
169
|
-
return exploded.join(
|
177
|
+
return exploded.join('');
|
170
178
|
};
|
171
179
|
|
172
180
|
// custom formatter methods
|
@@ -178,14 +186,14 @@ colors.maps = {};
|
|
178
186
|
colors.maps.america = require('./maps/america');
|
179
187
|
colors.maps.zebra = require('./maps/zebra');
|
180
188
|
colors.maps.rainbow = require('./maps/rainbow');
|
181
|
-
colors.maps.random = require('./maps/random')
|
189
|
+
colors.maps.random = require('./maps/random');
|
182
190
|
|
183
191
|
for (var map in colors.maps) {
|
184
|
-
(function(map){
|
185
|
-
colors[map] = function
|
192
|
+
(function(map) {
|
193
|
+
colors[map] = function(str) {
|
186
194
|
return sequencer(colors.maps[map], str);
|
187
|
-
}
|
188
|
-
})(map)
|
195
|
+
};
|
196
|
+
})(map);
|
189
197
|
}
|
190
198
|
|
191
199
|
defineProps(colors, init());
|
package/lib/custom/trap.js
CHANGED
@@ -1,45 +1,46 @@
|
|
1
|
-
module['exports'] = function runTheTrap
|
2
|
-
var result =
|
3
|
-
text = text ||
|
1
|
+
module['exports'] = function runTheTrap(text, options) {
|
2
|
+
var result = '';
|
3
|
+
text = text || 'Run the trap, drop the bass';
|
4
4
|
text = text.split('');
|
5
5
|
var trap = {
|
6
|
-
a: [
|
7
|
-
b: [
|
8
|
-
c: [
|
9
|
-
d: [
|
10
|
-
e: [
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
6
|
+
a: ['\u0040', '\u0104', '\u023a', '\u0245', '\u0394', '\u039b', '\u0414'],
|
7
|
+
b: ['\u00df', '\u0181', '\u0243', '\u026e', '\u03b2', '\u0e3f'],
|
8
|
+
c: ['\u00a9', '\u023b', '\u03fe'],
|
9
|
+
d: ['\u00d0', '\u018a', '\u0500', '\u0501', '\u0502', '\u0503'],
|
10
|
+
e: ['\u00cb', '\u0115', '\u018e', '\u0258', '\u03a3', '\u03be', '\u04bc',
|
11
|
+
'\u0a6c'],
|
12
|
+
f: ['\u04fa'],
|
13
|
+
g: ['\u0262'],
|
14
|
+
h: ['\u0126', '\u0195', '\u04a2', '\u04ba', '\u04c7', '\u050a'],
|
15
|
+
i: ['\u0f0f'],
|
16
|
+
j: ['\u0134'],
|
17
|
+
k: ['\u0138', '\u04a0', '\u04c3', '\u051e'],
|
18
|
+
l: ['\u0139'],
|
19
|
+
m: ['\u028d', '\u04cd', '\u04ce', '\u0520', '\u0521', '\u0d69'],
|
20
|
+
n: ['\u00d1', '\u014b', '\u019d', '\u0376', '\u03a0', '\u048a'],
|
21
|
+
o: ['\u00d8', '\u00f5', '\u00f8', '\u01fe', '\u0298', '\u047a', '\u05dd',
|
22
|
+
'\u06dd', '\u0e4f'],
|
23
|
+
p: ['\u01f7', '\u048e'],
|
24
|
+
q: ['\u09cd'],
|
25
|
+
r: ['\u00ae', '\u01a6', '\u0210', '\u024c', '\u0280', '\u042f'],
|
26
|
+
s: ['\u00a7', '\u03de', '\u03df', '\u03e8'],
|
27
|
+
t: ['\u0141', '\u0166', '\u0373'],
|
28
|
+
u: ['\u01b1', '\u054d'],
|
29
|
+
v: ['\u05d8'],
|
30
|
+
w: ['\u0428', '\u0460', '\u047c', '\u0d70'],
|
31
|
+
x: ['\u04b2', '\u04fe', '\u04fc', '\u04fd'],
|
32
|
+
y: ['\u00a5', '\u04b0', '\u04cb'],
|
33
|
+
z: ['\u01b5', '\u0240'],
|
34
|
+
};
|
35
|
+
text.forEach(function(c) {
|
34
36
|
c = c.toLowerCase();
|
35
|
-
var chars = trap[c] || [
|
37
|
+
var chars = trap[c] || [' '];
|
36
38
|
var rand = Math.floor(Math.random() * chars.length);
|
37
|
-
if (typeof trap[c] !==
|
39
|
+
if (typeof trap[c] !== 'undefined') {
|
38
40
|
result += trap[c][rand];
|
39
41
|
} else {
|
40
42
|
result += c;
|
41
43
|
}
|
42
44
|
});
|
43
45
|
return result;
|
44
|
-
|
45
|
-
}
|
46
|
+
};
|
package/lib/custom/zalgo.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
// please no
|
2
2
|
module['exports'] = function zalgo(text, options) {
|
3
|
-
text = text ||
|
3
|
+
text = text || ' he is here ';
|
4
4
|
var soul = {
|
5
|
-
|
5
|
+
'up': [
|
6
6
|
'̍', '̎', '̄', '̅',
|
7
7
|
'̿', '̑', '̆', '̐',
|
8
8
|
'͒', '͗', '͑', '̇',
|
@@ -15,9 +15,9 @@ module['exports'] = function zalgo(text, options) {
|
|
15
15
|
'ͦ', 'ͧ', 'ͨ', 'ͩ',
|
16
16
|
'ͪ', 'ͫ', 'ͬ', 'ͭ',
|
17
17
|
'ͮ', 'ͯ', '̾', '͛',
|
18
|
-
'͆', '̚'
|
18
|
+
'͆', '̚',
|
19
19
|
],
|
20
|
-
|
20
|
+
'down': [
|
21
21
|
'̖', '̗', '̘', '̙',
|
22
22
|
'̜', '̝', '̞', '̟',
|
23
23
|
'̠', '̤', '̥', '̦',
|
@@ -27,48 +27,53 @@ module['exports'] = function zalgo(text, options) {
|
|
27
27
|
'̺', '̻', '̼', 'ͅ',
|
28
28
|
'͇', '͈', '͉', '͍',
|
29
29
|
'͎', '͓', '͔', '͕',
|
30
|
-
'͖', '͙', '͚', '̣'
|
30
|
+
'͖', '͙', '͚', '̣',
|
31
31
|
],
|
32
|
-
|
32
|
+
'mid': [
|
33
33
|
'̕', '̛', '̀', '́',
|
34
34
|
'͘', '̡', '̢', '̧',
|
35
35
|
'̨', '̴', '̵', '̶',
|
36
36
|
'͜', '͝', '͞',
|
37
37
|
'͟', '͠', '͢', '̸',
|
38
|
-
'̷', '͡', ' ҉'
|
39
|
-
]
|
40
|
-
}
|
41
|
-
all = [].concat(soul.up, soul.down, soul.mid)
|
42
|
-
zalgo = {};
|
38
|
+
'̷', '͡', ' ҉',
|
39
|
+
],
|
40
|
+
};
|
41
|
+
var all = [].concat(soul.up, soul.down, soul.mid);
|
43
42
|
|
44
43
|
function randomNumber(range) {
|
45
44
|
var r = Math.floor(Math.random() * range);
|
46
45
|
return r;
|
47
46
|
}
|
48
47
|
|
49
|
-
function
|
48
|
+
function isChar(character) {
|
50
49
|
var bool = false;
|
51
|
-
all.filter(function
|
50
|
+
all.filter(function(i) {
|
52
51
|
bool = (i === character);
|
53
52
|
});
|
54
53
|
return bool;
|
55
54
|
}
|
56
|
-
|
55
|
+
|
57
56
|
|
58
57
|
function heComes(text, options) {
|
59
|
-
var result = ''
|
58
|
+
var result = '';
|
59
|
+
var counts;
|
60
|
+
var l;
|
60
61
|
options = options || {};
|
61
|
-
options[
|
62
|
-
|
63
|
-
options[
|
64
|
-
|
62
|
+
options['up'] =
|
63
|
+
typeof options['up'] !== 'undefined' ? options['up'] : true;
|
64
|
+
options['mid'] =
|
65
|
+
typeof options['mid'] !== 'undefined' ? options['mid'] : true;
|
66
|
+
options['down'] =
|
67
|
+
typeof options['down'] !== 'undefined' ? options['down'] : true;
|
68
|
+
options['size'] =
|
69
|
+
typeof options['size'] !== 'undefined' ? options['size'] : 'maxi';
|
65
70
|
text = text.split('');
|
66
71
|
for (l in text) {
|
67
|
-
if (
|
72
|
+
if (isChar(l)) {
|
68
73
|
continue;
|
69
74
|
}
|
70
75
|
result = result + text[l];
|
71
|
-
counts = {
|
76
|
+
counts = {'up': 0, 'down': 0, 'mid': 0};
|
72
77
|
switch (options.size) {
|
73
78
|
case 'mini':
|
74
79
|
counts.up = randomNumber(8);
|
@@ -87,10 +92,10 @@ module['exports'] = function zalgo(text, options) {
|
|
87
92
|
break;
|
88
93
|
}
|
89
94
|
|
90
|
-
var arr = [
|
95
|
+
var arr = ['up', 'mid', 'down'];
|
91
96
|
for (var d in arr) {
|
92
97
|
var index = arr[d];
|
93
|
-
for (var i = 0
|
98
|
+
for (var i = 0; i <= counts[index]; i++) {
|
94
99
|
if (options[index]) {
|
95
100
|
result = result + soul[index][randomNumber(soul[index].length)];
|
96
101
|
}
|
@@ -101,4 +106,5 @@ module['exports'] = function zalgo(text, options) {
|
|
101
106
|
}
|
102
107
|
// don't summon him
|
103
108
|
return heComes(text, options);
|
104
|
-
}
|
109
|
+
};
|
110
|
+
|
@@ -1,43 +1,42 @@
|
|
1
1
|
var colors = require('./colors');
|
2
2
|
|
3
|
-
module['exports'] = function
|
4
|
-
|
3
|
+
module['exports'] = function() {
|
5
4
|
//
|
6
5
|
// Extends prototype of native string object to allow for "foo".red syntax
|
7
6
|
//
|
8
|
-
var addProperty = function
|
7
|
+
var addProperty = function(color, func) {
|
9
8
|
String.prototype.__defineGetter__(color, func);
|
10
9
|
};
|
11
10
|
|
12
|
-
addProperty('strip', function
|
11
|
+
addProperty('strip', function() {
|
13
12
|
return colors.strip(this);
|
14
13
|
});
|
15
14
|
|
16
|
-
addProperty('stripColors', function
|
15
|
+
addProperty('stripColors', function() {
|
17
16
|
return colors.strip(this);
|
18
17
|
});
|
19
18
|
|
20
|
-
addProperty(
|
19
|
+
addProperty('trap', function() {
|
21
20
|
return colors.trap(this);
|
22
21
|
});
|
23
22
|
|
24
|
-
addProperty(
|
23
|
+
addProperty('zalgo', function() {
|
25
24
|
return colors.zalgo(this);
|
26
25
|
});
|
27
26
|
|
28
|
-
addProperty(
|
27
|
+
addProperty('zebra', function() {
|
29
28
|
return colors.zebra(this);
|
30
29
|
});
|
31
30
|
|
32
|
-
addProperty(
|
31
|
+
addProperty('rainbow', function() {
|
33
32
|
return colors.rainbow(this);
|
34
33
|
});
|
35
34
|
|
36
|
-
addProperty(
|
35
|
+
addProperty('random', function() {
|
37
36
|
return colors.random(this);
|
38
37
|
});
|
39
38
|
|
40
|
-
addProperty(
|
39
|
+
addProperty('america', function() {
|
41
40
|
return colors.america(this);
|
42
41
|
});
|
43
42
|
|
@@ -45,8 +44,8 @@ module['exports'] = function () {
|
|
45
44
|
// Iterate through all default styles and colors
|
46
45
|
//
|
47
46
|
var x = Object.keys(colors.styles);
|
48
|
-
x.forEach(function
|
49
|
-
addProperty(style, function
|
47
|
+
x.forEach(function(style) {
|
48
|
+
addProperty(style, function() {
|
50
49
|
return colors.stylize(this, style);
|
51
50
|
});
|
52
51
|
});
|
@@ -57,25 +56,28 @@ module['exports'] = function () {
|
|
57
56
|
// on String that you should not overwrite.
|
58
57
|
//
|
59
58
|
var stringPrototypeBlacklist = [
|
60
|
-
'__defineGetter__', '__defineSetter__', '__lookupGetter__',
|
61
|
-
'
|
62
|
-
'
|
63
|
-
'
|
59
|
+
'__defineGetter__', '__defineSetter__', '__lookupGetter__',
|
60
|
+
'__lookupSetter__', 'charAt', 'constructor', 'hasOwnProperty',
|
61
|
+
'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString',
|
62
|
+
'valueOf', 'charCodeAt', 'indexOf', 'lastIndexOf', 'length',
|
63
|
+
'localeCompare', 'match', 'repeat', 'replace', 'search', 'slice',
|
64
|
+
'split', 'substring', 'toLocaleLowerCase', 'toLocaleUpperCase',
|
65
|
+
'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight',
|
64
66
|
];
|
65
67
|
|
66
|
-
Object.keys(theme).forEach(function
|
68
|
+
Object.keys(theme).forEach(function(prop) {
|
67
69
|
if (stringPrototypeBlacklist.indexOf(prop) !== -1) {
|
68
|
-
console.log('warn: '.red + ('String.prototype' + prop).magenta +
|
69
|
-
|
70
|
-
|
70
|
+
console.log('warn: '.red + ('String.prototype' + prop).magenta +
|
71
|
+
' is probably something you don\'t want to override. ' +
|
72
|
+
'Ignoring style name');
|
73
|
+
} else {
|
71
74
|
if (typeof(theme[prop]) === 'string') {
|
72
75
|
colors[prop] = colors[theme[prop]];
|
73
|
-
addProperty(prop, function
|
76
|
+
addProperty(prop, function() {
|
74
77
|
return colors[theme[prop]](this);
|
75
78
|
});
|
76
|
-
}
|
77
|
-
|
78
|
-
addProperty(prop, function () {
|
79
|
+
} else {
|
80
|
+
addProperty(prop, function() {
|
79
81
|
var ret = this;
|
80
82
|
for (var t = 0; t < theme[prop].length; t++) {
|
81
83
|
ret = colors[theme[prop][t]](ret);
|
@@ -87,19 +89,18 @@ module['exports'] = function () {
|
|
87
89
|
});
|
88
90
|
}
|
89
91
|
|
90
|
-
colors.setTheme = function
|
92
|
+
colors.setTheme = function(theme) {
|
91
93
|
if (typeof theme === 'string') {
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
94
|
+
console.log('colors.setTheme now only accepts an object, not a string. ' +
|
95
|
+
'If you are trying to set a theme from a file, it is now your (the ' +
|
96
|
+
'caller\'s) responsibility to require the file. The old syntax ' +
|
97
|
+
'looked like colors.setTheme(__dirname + ' +
|
98
|
+
'\'/../themes/generic-logging.js\'); The new syntax looks like '+
|
99
|
+
'colors.setTheme(require(__dirname + ' +
|
100
|
+
'\'/../themes/generic-logging.js\'));');
|
101
|
+
return;
|
100
102
|
} else {
|
101
103
|
applyTheme(theme);
|
102
104
|
}
|
103
105
|
};
|
104
|
-
|
105
106
|
};
|
package/lib/index.js
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
var colors = require('./colors');
|
2
2
|
module['exports'] = colors;
|
3
3
|
|
4
|
-
// Remark: By default, colors will add style properties to String.prototype
|
4
|
+
// Remark: By default, colors will add style properties to String.prototype.
|
5
5
|
//
|
6
|
-
// If you don't wish to extend String.prototype you can do this instead and
|
6
|
+
// If you don't wish to extend String.prototype, you can do this instead and
|
7
|
+
// native String will not be touched:
|
7
8
|
//
|
8
9
|
// var colors = require('colors/safe);
|
9
10
|
// colors.red("foo")
|
10
11
|
//
|
11
12
|
//
|
12
|
-
require('./extendStringPrototype')();
|
13
|
+
require('./extendStringPrototype')();
|
package/lib/maps/america.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
var colors = require('../colors');
|
2
2
|
|
3
3
|
module['exports'] = (function() {
|
4
|
-
return function
|
5
|
-
if(letter ===
|
6
|
-
switch(i%3) {
|
4
|
+
return function(letter, i, exploded) {
|
5
|
+
if (letter === ' ') return letter;
|
6
|
+
switch (i%3) {
|
7
7
|
case 0: return colors.red(letter);
|
8
|
-
case 1: return colors.white(letter)
|
9
|
-
case 2: return colors.blue(letter)
|
8
|
+
case 1: return colors.white(letter);
|
9
|
+
case 2: return colors.blue(letter);
|
10
10
|
}
|
11
|
-
}
|
12
|
-
})();
|
11
|
+
};
|
12
|
+
})();
|
package/lib/maps/rainbow.js
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
var colors = require('../colors');
|
2
2
|
|
3
|
-
module['exports'] = (function
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module['exports'] = (function() {
|
4
|
+
// RoY G BiV
|
5
|
+
var rainbowColors = ['red', 'yellow', 'green', 'blue', 'magenta'];
|
6
|
+
return function(letter, i, exploded) {
|
7
|
+
if (letter === ' ') {
|
7
8
|
return letter;
|
8
9
|
} else {
|
9
10
|
return colors[rainbowColors[i++ % rainbowColors.length]](letter);
|
package/lib/maps/random.js
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
var colors = require('../colors');
|
2
2
|
|
3
|
-
module['exports'] = (function
|
4
|
-
var available = ['underline', 'inverse', 'grey', 'yellow', 'red', 'green',
|
3
|
+
module['exports'] = (function() {
|
4
|
+
var available = ['underline', 'inverse', 'grey', 'yellow', 'red', 'green',
|
5
|
+
'blue', 'white', 'cyan', 'magenta'];
|
5
6
|
return function(letter, i, exploded) {
|
6
|
-
return letter ===
|
7
|
+
return letter === ' ' ? letter :
|
8
|
+
colors[
|
9
|
+
available[Math.round(Math.random() * (available.length - 2))]
|
10
|
+
](letter);
|
7
11
|
};
|
8
|
-
})();
|
12
|
+
})();
|
package/lib/maps/zebra.js
CHANGED
package/lib/styles.js
CHANGED
@@ -65,13 +65,13 @@ var codes = {
|
|
65
65
|
blueBG: [44, 49],
|
66
66
|
magentaBG: [45, 49],
|
67
67
|
cyanBG: [46, 49],
|
68
|
-
whiteBG: [47, 49]
|
68
|
+
whiteBG: [47, 49],
|
69
69
|
|
70
70
|
};
|
71
71
|
|
72
|
-
Object.keys(codes).forEach(function
|
72
|
+
Object.keys(codes).forEach(function(key) {
|
73
73
|
var val = codes[key];
|
74
74
|
var style = styles[key] = [];
|
75
75
|
style.open = '\u001b[' + val[0] + 'm';
|
76
76
|
style.close = '\u001b[' + val[1] + 'm';
|
77
|
-
});
|
77
|
+
});
|
package/lib/system/has-flag.js
CHANGED
@@ -3,21 +3,33 @@ MIT License
|
|
3
3
|
|
4
4
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
5
5
|
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
7
|
+
this software and associated documentation files (the "Software"), to deal in
|
8
|
+
the Software without restriction, including without limitation the rights to
|
9
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
10
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
11
|
+
so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
14
|
+
copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
SOFTWARE.
|
11
23
|
*/
|
12
24
|
|
13
25
|
'use strict';
|
14
26
|
|
15
|
-
module.exports = function
|
16
|
-
|
27
|
+
module.exports = function(flag, argv) {
|
28
|
+
argv = argv || process.argv;
|
17
29
|
|
18
|
-
|
19
|
-
|
20
|
-
|
30
|
+
var terminatorPos = argv.indexOf('--');
|
31
|
+
var prefix = /^-{1,2}/.test(flag) ? '' : '--';
|
32
|
+
var pos = argv.indexOf(prefix + flag);
|
21
33
|
|
22
|
-
|
34
|
+
return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
|
23
35
|
};
|
@@ -32,116 +32,120 @@ var env = process.env;
|
|
32
32
|
|
33
33
|
var forceColor = void 0;
|
34
34
|
if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
|
35
|
-
|
36
|
-
} else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true')
|
37
|
-
|
35
|
+
forceColor = false;
|
36
|
+
} else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true')
|
37
|
+
|| hasFlag('color=always')) {
|
38
|
+
forceColor = true;
|
38
39
|
}
|
39
40
|
if ('FORCE_COLOR' in env) {
|
40
|
-
|
41
|
+
forceColor = env.FORCE_COLOR.length === 0
|
42
|
+
|| parseInt(env.FORCE_COLOR, 10) !== 0;
|
41
43
|
}
|
42
44
|
|
43
45
|
function translateLevel(level) {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
if (level === 0) {
|
47
|
+
return false;
|
48
|
+
}
|
49
|
+
|
50
|
+
return {
|
51
|
+
level: level,
|
52
|
+
hasBasic: true,
|
53
|
+
has256: level >= 2,
|
54
|
+
has16m: level >= 3,
|
55
|
+
};
|
54
56
|
}
|
55
57
|
|
56
58
|
function supportsColor(stream) {
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
59
|
+
if (forceColor === false) {
|
60
|
+
return 0;
|
61
|
+
}
|
62
|
+
|
63
|
+
if (hasFlag('color=16m') || hasFlag('color=full')
|
64
|
+
|| hasFlag('color=truecolor')) {
|
65
|
+
return 3;
|
66
|
+
}
|
67
|
+
|
68
|
+
if (hasFlag('color=256')) {
|
69
|
+
return 2;
|
70
|
+
}
|
71
|
+
|
72
|
+
if (stream && !stream.isTTY && forceColor !== true) {
|
73
|
+
return 0;
|
74
|
+
}
|
75
|
+
|
76
|
+
var min = forceColor ? 1 : 0;
|
77
|
+
|
78
|
+
if (process.platform === 'win32') {
|
79
|
+
// Node.js 7.5.0 is the first version of Node.js to include a patch to
|
80
|
+
// libuv that enables 256 color output on Windows. Anything earlier and it
|
81
|
+
// won't work. However, here we target Node.js 8 at minimum as it is an LTS
|
82
|
+
// release, and Node.js 7 is not. Windows 10 build 10586 is the first
|
83
|
+
// Windows release that supports 256 colors. Windows 10 build 14931 is the
|
84
|
+
// first release that supports 16m/TrueColor.
|
85
|
+
var osRelease = os.release().split('.');
|
86
|
+
if (Number(process.versions.node.split('.')[0]) >= 8
|
87
|
+
&& Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
88
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
89
|
+
}
|
90
|
+
|
91
|
+
return 1;
|
92
|
+
}
|
93
|
+
|
94
|
+
if ('CI' in env) {
|
95
|
+
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(function(sign) {
|
96
|
+
return sign in env;
|
97
|
+
}) || env.CI_NAME === 'codeship') {
|
98
|
+
return 1;
|
99
|
+
}
|
100
|
+
|
101
|
+
return min;
|
102
|
+
}
|
103
|
+
|
104
|
+
if ('TEAMCITY_VERSION' in env) {
|
105
|
+
return (/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0
|
106
|
+
);
|
107
|
+
}
|
108
|
+
|
109
|
+
if ('TERM_PROGRAM' in env) {
|
110
|
+
var version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
111
|
+
|
112
|
+
switch (env.TERM_PROGRAM) {
|
113
|
+
case 'iTerm.app':
|
114
|
+
return version >= 3 ? 3 : 2;
|
115
|
+
case 'Hyper':
|
116
|
+
return 3;
|
117
|
+
case 'Apple_Terminal':
|
118
|
+
return 2;
|
119
|
+
// No default
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
124
|
+
return 2;
|
125
|
+
}
|
126
|
+
|
127
|
+
if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
128
|
+
return 1;
|
129
|
+
}
|
130
|
+
|
131
|
+
if ('COLORTERM' in env) {
|
132
|
+
return 1;
|
133
|
+
}
|
134
|
+
|
135
|
+
if (env.TERM === 'dumb') {
|
136
|
+
return min;
|
137
|
+
}
|
138
|
+
|
139
|
+
return min;
|
136
140
|
}
|
137
141
|
|
138
142
|
function getSupportLevel(stream) {
|
139
|
-
|
140
|
-
|
143
|
+
var level = supportsColor(stream);
|
144
|
+
return translateLevel(level);
|
141
145
|
}
|
142
146
|
|
143
147
|
module.exports = {
|
144
|
-
|
145
|
-
|
146
|
-
|
148
|
+
supportsColor: getSupportLevel,
|
149
|
+
stdout: getSupportLevel(process.stdout),
|
150
|
+
stderr: getSupportLevel(process.stderr),
|
147
151
|
};
|
package/package.json
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
{
|
2
2
|
"name": "colors",
|
3
3
|
"description": "get colors in your node.js console",
|
4
|
-
"version": "1.
|
4
|
+
"version": "1.3.0",
|
5
5
|
"author": "Marak Squires",
|
6
6
|
"homepage": "https://github.com/Marak/colors.js",
|
7
7
|
"bugs": "https://github.com/Marak/colors.js/issues",
|
8
|
-
"keywords": [
|
8
|
+
"keywords": [
|
9
|
+
"ansi",
|
10
|
+
"terminal",
|
11
|
+
"colors"
|
12
|
+
],
|
9
13
|
"repository": {
|
10
14
|
"type": "git",
|
11
15
|
"url": "http://github.com/Marak/colors.js.git"
|
12
16
|
},
|
13
17
|
"license": "MIT",
|
14
18
|
"scripts": {
|
15
|
-
|
19
|
+
"lint": "eslint . --fix",
|
20
|
+
"test": "node tests/basic-test.js && node tests/safe-test.js"
|
16
21
|
},
|
17
22
|
"engines": {
|
18
23
|
"node": ">=0.1.90"
|
@@ -26,5 +31,9 @@
|
|
26
31
|
"themes",
|
27
32
|
"index.d.ts",
|
28
33
|
"safe.d.ts"
|
29
|
-
]
|
34
|
+
],
|
35
|
+
"devDependencies": {
|
36
|
+
"eslint": "^4.19.1",
|
37
|
+
"eslint-config-google": "^0.9.1"
|
38
|
+
}
|
30
39
|
}
|
package/safe.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
//
|
2
|
-
// Remark: Requiring this file will use the "safe" colors API
|
2
|
+
// Remark: Requiring this file will use the "safe" colors API,
|
3
|
+
// which will not touch String.prototype.
|
3
4
|
//
|
4
5
|
// var colors = require('colors/safe');
|
5
6
|
// colors.red("foo")
|