colors 1.2.0 → 1.2.4
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/index.d.ts +136 -0
- package/lib/colors.js +59 -43
- package/lib/custom/trap.js +36 -35
- package/lib/custom/zalgo.js +30 -24
- package/lib/extendStringPrototype.js +28 -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 +16 -5
- package/safe.d.ts +48 -0
- package/safe.js +2 -1
- package/themes/generic-logging.js +2 -2
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,51 +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
|
-
|
13
|
-
return function () {
|
14
|
-
var exploded = this.split(""), i = 0;
|
15
|
-
exploded = exploded.map(map);
|
16
|
-
return exploded.join("");
|
17
|
-
}
|
18
|
-
};
|
19
|
-
|
20
|
-
addProperty('strip', function () {
|
11
|
+
addProperty('strip', function() {
|
21
12
|
return colors.strip(this);
|
22
13
|
});
|
23
14
|
|
24
|
-
addProperty('stripColors', function
|
15
|
+
addProperty('stripColors', function() {
|
25
16
|
return colors.strip(this);
|
26
17
|
});
|
27
18
|
|
28
|
-
addProperty(
|
19
|
+
addProperty('trap', function() {
|
29
20
|
return colors.trap(this);
|
30
21
|
});
|
31
22
|
|
32
|
-
addProperty(
|
23
|
+
addProperty('zalgo', function() {
|
33
24
|
return colors.zalgo(this);
|
34
25
|
});
|
35
26
|
|
36
|
-
addProperty(
|
27
|
+
addProperty('zebra', function() {
|
37
28
|
return colors.zebra(this);
|
38
29
|
});
|
39
30
|
|
40
|
-
addProperty(
|
31
|
+
addProperty('rainbow', function() {
|
41
32
|
return colors.rainbow(this);
|
42
33
|
});
|
43
34
|
|
44
|
-
addProperty(
|
35
|
+
addProperty('random', function() {
|
45
36
|
return colors.random(this);
|
46
37
|
});
|
47
38
|
|
48
|
-
addProperty(
|
39
|
+
addProperty('america', function() {
|
49
40
|
return colors.america(this);
|
50
41
|
});
|
51
42
|
|
@@ -53,8 +44,8 @@ module['exports'] = function () {
|
|
53
44
|
// Iterate through all default styles and colors
|
54
45
|
//
|
55
46
|
var x = Object.keys(colors.styles);
|
56
|
-
x.forEach(function
|
57
|
-
addProperty(style, function
|
47
|
+
x.forEach(function(style) {
|
48
|
+
addProperty(style, function() {
|
58
49
|
return colors.stylize(this, style);
|
59
50
|
});
|
60
51
|
});
|
@@ -65,25 +56,28 @@ module['exports'] = function () {
|
|
65
56
|
// on String that you should not overwrite.
|
66
57
|
//
|
67
58
|
var stringPrototypeBlacklist = [
|
68
|
-
'__defineGetter__', '__defineSetter__', '__lookupGetter__',
|
69
|
-
'
|
70
|
-
'
|
71
|
-
'
|
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',
|
72
66
|
];
|
73
67
|
|
74
|
-
Object.keys(theme).forEach(function
|
68
|
+
Object.keys(theme).forEach(function(prop) {
|
75
69
|
if (stringPrototypeBlacklist.indexOf(prop) !== -1) {
|
76
|
-
console.log('warn: '.red + ('String.prototype' + prop).magenta +
|
77
|
-
|
78
|
-
|
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 {
|
79
74
|
if (typeof(theme[prop]) === 'string') {
|
80
75
|
colors[prop] = colors[theme[prop]];
|
81
|
-
addProperty(prop, function
|
76
|
+
addProperty(prop, function() {
|
82
77
|
return colors[theme[prop]](this);
|
83
78
|
});
|
84
|
-
}
|
85
|
-
|
86
|
-
addProperty(prop, function () {
|
79
|
+
} else {
|
80
|
+
addProperty(prop, function() {
|
87
81
|
var ret = this;
|
88
82
|
for (var t = 0; t < theme[prop].length; t++) {
|
89
83
|
ret = colors[theme[prop][t]](ret);
|
@@ -95,7 +89,7 @@ module['exports'] = function () {
|
|
95
89
|
});
|
96
90
|
}
|
97
91
|
|
98
|
-
colors.setTheme = function
|
92
|
+
colors.setTheme = function(theme) {
|
99
93
|
if (typeof theme === 'string') {
|
100
94
|
try {
|
101
95
|
colors.themes[theme] = require(theme);
|
@@ -109,5 +103,4 @@ module['exports'] = function () {
|
|
109
103
|
applyTheme(theme);
|
110
104
|
}
|
111
105
|
};
|
112
|
-
|
113
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.2.
|
4
|
+
"version": "1.2.4",
|
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"
|
@@ -23,6 +28,12 @@
|
|
23
28
|
"lib",
|
24
29
|
"LICENSE",
|
25
30
|
"safe.js",
|
26
|
-
"themes"
|
27
|
-
|
31
|
+
"themes",
|
32
|
+
"index.d.ts",
|
33
|
+
"safe.d.ts"
|
34
|
+
],
|
35
|
+
"devDependencies": {
|
36
|
+
"eslint": "^4.19.1",
|
37
|
+
"eslint-config-google": "^0.9.1"
|
38
|
+
}
|
28
39
|
}
|