colors 1.2.1 → 1.2.5
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/LICENSE +25 -25
- package/README.md +184 -184
- package/examples/normal-usage.js +81 -78
- package/examples/safe-string.js +77 -76
- package/index.d.ts +136 -134
- package/lib/colors.js +199 -179
- package/lib/custom/trap.js +46 -45
- package/lib/custom/zalgo.js +110 -104
- package/lib/extendStringPrototype.js +106 -113
- package/lib/index.js +13 -12
- package/lib/maps/america.js +12 -12
- package/lib/maps/rainbow.js +14 -13
- package/lib/maps/random.js +12 -8
- package/lib/maps/zebra.js +5 -5
- package/lib/styles.js +77 -77
- package/lib/system/has-flag.js +35 -23
- package/lib/system/supports-colors.js +151 -147
- package/package.json +39 -30
- package/safe.d.ts +48 -45
- package/safe.js +10 -9
- package/themes/generic-logging.js +12 -12
package/lib/custom/zalgo.js
CHANGED
@@ -1,104 +1,110 @@
|
|
1
|
-
// please no
|
2
|
-
module['exports'] = function zalgo(text, options) {
|
3
|
-
text = text ||
|
4
|
-
var soul = {
|
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
|
-
all = [].concat(soul.up, soul.down, soul.mid)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
var
|
60
|
-
|
61
|
-
options
|
62
|
-
options[
|
63
|
-
|
64
|
-
options[
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
case '
|
79
|
-
counts.up = randomNumber(
|
80
|
-
counts.mid = randomNumber(
|
81
|
-
counts.down = randomNumber(
|
82
|
-
break;
|
83
|
-
|
84
|
-
counts.up = randomNumber(
|
85
|
-
counts.mid = randomNumber(
|
86
|
-
counts.down = randomNumber(
|
87
|
-
break;
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
}
|
1
|
+
// please no
|
2
|
+
module['exports'] = function zalgo(text, options) {
|
3
|
+
text = text || ' he is here ';
|
4
|
+
var soul = {
|
5
|
+
'up': [
|
6
|
+
'̍', '̎', '̄', '̅',
|
7
|
+
'̿', '̑', '̆', '̐',
|
8
|
+
'͒', '͗', '͑', '̇',
|
9
|
+
'̈', '̊', '͂', '̓',
|
10
|
+
'̈', '͊', '͋', '͌',
|
11
|
+
'̃', '̂', '̌', '͐',
|
12
|
+
'̀', '́', '̋', '̏',
|
13
|
+
'̒', '̓', '̔', '̽',
|
14
|
+
'̉', 'ͣ', 'ͤ', 'ͥ',
|
15
|
+
'ͦ', 'ͧ', 'ͨ', 'ͩ',
|
16
|
+
'ͪ', 'ͫ', 'ͬ', 'ͭ',
|
17
|
+
'ͮ', 'ͯ', '̾', '͛',
|
18
|
+
'͆', '̚',
|
19
|
+
],
|
20
|
+
'down': [
|
21
|
+
'̖', '̗', '̘', '̙',
|
22
|
+
'̜', '̝', '̞', '̟',
|
23
|
+
'̠', '̤', '̥', '̦',
|
24
|
+
'̩', '̪', '̫', '̬',
|
25
|
+
'̭', '̮', '̯', '̰',
|
26
|
+
'̱', '̲', '̳', '̹',
|
27
|
+
'̺', '̻', '̼', 'ͅ',
|
28
|
+
'͇', '͈', '͉', '͍',
|
29
|
+
'͎', '͓', '͔', '͕',
|
30
|
+
'͖', '͙', '͚', '̣',
|
31
|
+
],
|
32
|
+
'mid': [
|
33
|
+
'̕', '̛', '̀', '́',
|
34
|
+
'͘', '̡', '̢', '̧',
|
35
|
+
'̨', '̴', '̵', '̶',
|
36
|
+
'͜', '͝', '͞',
|
37
|
+
'͟', '͠', '͢', '̸',
|
38
|
+
'̷', '͡', ' ҉',
|
39
|
+
],
|
40
|
+
};
|
41
|
+
var all = [].concat(soul.up, soul.down, soul.mid);
|
42
|
+
|
43
|
+
function randomNumber(range) {
|
44
|
+
var r = Math.floor(Math.random() * range);
|
45
|
+
return r;
|
46
|
+
}
|
47
|
+
|
48
|
+
function isChar(character) {
|
49
|
+
var bool = false;
|
50
|
+
all.filter(function(i) {
|
51
|
+
bool = (i === character);
|
52
|
+
});
|
53
|
+
return bool;
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
function heComes(text, options) {
|
58
|
+
var result = '';
|
59
|
+
var counts;
|
60
|
+
var l;
|
61
|
+
options = options || {};
|
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';
|
70
|
+
text = text.split('');
|
71
|
+
for (l in text) {
|
72
|
+
if (isChar(l)) {
|
73
|
+
continue;
|
74
|
+
}
|
75
|
+
result = result + text[l];
|
76
|
+
counts = {'up': 0, 'down': 0, 'mid': 0};
|
77
|
+
switch (options.size) {
|
78
|
+
case 'mini':
|
79
|
+
counts.up = randomNumber(8);
|
80
|
+
counts.mid = randomNumber(2);
|
81
|
+
counts.down = randomNumber(8);
|
82
|
+
break;
|
83
|
+
case 'maxi':
|
84
|
+
counts.up = randomNumber(16) + 3;
|
85
|
+
counts.mid = randomNumber(4) + 1;
|
86
|
+
counts.down = randomNumber(64) + 3;
|
87
|
+
break;
|
88
|
+
default:
|
89
|
+
counts.up = randomNumber(8) + 1;
|
90
|
+
counts.mid = randomNumber(6) / 2;
|
91
|
+
counts.down = randomNumber(8) + 1;
|
92
|
+
break;
|
93
|
+
}
|
94
|
+
|
95
|
+
var arr = ['up', 'mid', 'down'];
|
96
|
+
for (var d in arr) {
|
97
|
+
var index = arr[d];
|
98
|
+
for (var i = 0; i <= counts[index]; i++) {
|
99
|
+
if (options[index]) {
|
100
|
+
result = result + soul[index][randomNumber(soul[index].length)];
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
return result;
|
106
|
+
}
|
107
|
+
// don't summon him
|
108
|
+
return heComes(text, options);
|
109
|
+
};
|
110
|
+
|
@@ -1,113 +1,106 @@
|
|
1
|
-
var colors = require('./colors');
|
2
|
-
|
3
|
-
module['exports'] = function
|
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
|
-
|
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
|
-
} else {
|
109
|
-
applyTheme(theme);
|
110
|
-
}
|
111
|
-
};
|
112
|
-
|
113
|
-
};
|
1
|
+
var colors = require('./colors');
|
2
|
+
|
3
|
+
module['exports'] = function() {
|
4
|
+
//
|
5
|
+
// Extends prototype of native string object to allow for "foo".red syntax
|
6
|
+
//
|
7
|
+
var addProperty = function(color, func) {
|
8
|
+
String.prototype.__defineGetter__(color, func);
|
9
|
+
};
|
10
|
+
|
11
|
+
addProperty('strip', function() {
|
12
|
+
return colors.strip(this);
|
13
|
+
});
|
14
|
+
|
15
|
+
addProperty('stripColors', function() {
|
16
|
+
return colors.strip(this);
|
17
|
+
});
|
18
|
+
|
19
|
+
addProperty('trap', function() {
|
20
|
+
return colors.trap(this);
|
21
|
+
});
|
22
|
+
|
23
|
+
addProperty('zalgo', function() {
|
24
|
+
return colors.zalgo(this);
|
25
|
+
});
|
26
|
+
|
27
|
+
addProperty('zebra', function() {
|
28
|
+
return colors.zebra(this);
|
29
|
+
});
|
30
|
+
|
31
|
+
addProperty('rainbow', function() {
|
32
|
+
return colors.rainbow(this);
|
33
|
+
});
|
34
|
+
|
35
|
+
addProperty('random', function() {
|
36
|
+
return colors.random(this);
|
37
|
+
});
|
38
|
+
|
39
|
+
addProperty('america', function() {
|
40
|
+
return colors.america(this);
|
41
|
+
});
|
42
|
+
|
43
|
+
//
|
44
|
+
// Iterate through all default styles and colors
|
45
|
+
//
|
46
|
+
var x = Object.keys(colors.styles);
|
47
|
+
x.forEach(function(style) {
|
48
|
+
addProperty(style, function() {
|
49
|
+
return colors.stylize(this, style);
|
50
|
+
});
|
51
|
+
});
|
52
|
+
|
53
|
+
function applyTheme(theme) {
|
54
|
+
//
|
55
|
+
// Remark: This is a list of methods that exist
|
56
|
+
// on String that you should not overwrite.
|
57
|
+
//
|
58
|
+
var stringPrototypeBlacklist = [
|
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',
|
66
|
+
];
|
67
|
+
|
68
|
+
Object.keys(theme).forEach(function(prop) {
|
69
|
+
if (stringPrototypeBlacklist.indexOf(prop) !== -1) {
|
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 {
|
74
|
+
if (typeof(theme[prop]) === 'string') {
|
75
|
+
colors[prop] = colors[theme[prop]];
|
76
|
+
addProperty(prop, function() {
|
77
|
+
return colors[theme[prop]](this);
|
78
|
+
});
|
79
|
+
} else {
|
80
|
+
addProperty(prop, function() {
|
81
|
+
var ret = this;
|
82
|
+
for (var t = 0; t < theme[prop].length; t++) {
|
83
|
+
ret = colors[theme[prop][t]](ret);
|
84
|
+
}
|
85
|
+
return ret;
|
86
|
+
});
|
87
|
+
}
|
88
|
+
}
|
89
|
+
});
|
90
|
+
}
|
91
|
+
|
92
|
+
colors.setTheme = function(theme) {
|
93
|
+
if (typeof theme === 'string') {
|
94
|
+
try {
|
95
|
+
colors.themes[theme] = require(theme);
|
96
|
+
applyTheme(colors.themes[theme]);
|
97
|
+
return colors.themes[theme];
|
98
|
+
} catch (err) {
|
99
|
+
console.log(err);
|
100
|
+
return err;
|
101
|
+
}
|
102
|
+
} else {
|
103
|
+
applyTheme(theme);
|
104
|
+
}
|
105
|
+
};
|
106
|
+
};
|
package/lib/index.js
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
var colors = require('./colors');
|
2
|
-
module['exports'] = colors;
|
3
|
-
|
4
|
-
// Remark: By default, colors will add style properties to String.prototype
|
5
|
-
//
|
6
|
-
// If you don't wish to extend String.prototype you can do this instead and
|
7
|
-
//
|
8
|
-
//
|
9
|
-
// colors
|
10
|
-
//
|
11
|
-
//
|
12
|
-
|
1
|
+
var colors = require('./colors');
|
2
|
+
module['exports'] = colors;
|
3
|
+
|
4
|
+
// Remark: By default, colors will add style properties to String.prototype.
|
5
|
+
//
|
6
|
+
// If you don't wish to extend String.prototype, you can do this instead and
|
7
|
+
// native String will not be touched:
|
8
|
+
//
|
9
|
+
// var colors = require('colors/safe);
|
10
|
+
// colors.red("foo")
|
11
|
+
//
|
12
|
+
//
|
13
|
+
require('./extendStringPrototype')();
|
package/lib/maps/america.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
var colors = require('../colors');
|
2
|
-
|
3
|
-
module['exports'] = (function() {
|
4
|
-
return function
|
5
|
-
if(letter ===
|
6
|
-
switch(i%3) {
|
7
|
-
case 0: return colors.red(letter);
|
8
|
-
case 1: return colors.white(letter)
|
9
|
-
case 2: return colors.blue(letter)
|
10
|
-
}
|
11
|
-
}
|
12
|
-
})();
|
1
|
+
var colors = require('../colors');
|
2
|
+
|
3
|
+
module['exports'] = (function() {
|
4
|
+
return function(letter, i, exploded) {
|
5
|
+
if (letter === ' ') return letter;
|
6
|
+
switch (i%3) {
|
7
|
+
case 0: return colors.red(letter);
|
8
|
+
case 1: return colors.white(letter);
|
9
|
+
case 2: return colors.blue(letter);
|
10
|
+
}
|
11
|
+
};
|
12
|
+
})();
|
package/lib/maps/rainbow.js
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
var colors = require('../colors');
|
2
|
-
|
3
|
-
module['exports'] = (function
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
}
|
13
|
-
|
1
|
+
var colors = require('../colors');
|
2
|
+
|
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 === ' ') {
|
8
|
+
return letter;
|
9
|
+
} else {
|
10
|
+
return colors[rainbowColors[i++ % rainbowColors.length]](letter);
|
11
|
+
}
|
12
|
+
};
|
13
|
+
})();
|
14
|
+
|
package/lib/maps/random.js
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
var colors = require('../colors');
|
2
|
-
|
3
|
-
module['exports'] = (function
|
4
|
-
var available = ['underline', 'inverse', 'grey', 'yellow', 'red', 'green',
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
var colors = require('../colors');
|
2
|
+
|
3
|
+
module['exports'] = (function() {
|
4
|
+
var available = ['underline', 'inverse', 'grey', 'yellow', 'red', 'green',
|
5
|
+
'blue', 'white', 'cyan', 'magenta'];
|
6
|
+
return function(letter, i, exploded) {
|
7
|
+
return letter === ' ' ? letter :
|
8
|
+
colors[
|
9
|
+
available[Math.round(Math.random() * (available.length - 2))]
|
10
|
+
](letter);
|
11
|
+
};
|
12
|
+
})();
|
package/lib/maps/zebra.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
var colors = require('../colors');
|
2
|
-
|
3
|
-
module['exports'] = function
|
4
|
-
return i % 2 === 0 ? letter : colors.inverse(letter);
|
5
|
-
};
|
1
|
+
var colors = require('../colors');
|
2
|
+
|
3
|
+
module['exports'] = function(letter, i, exploded) {
|
4
|
+
return i % 2 === 0 ? letter : colors.inverse(letter);
|
5
|
+
};
|