colors 0.6.2 → 1.0.3

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/colors.js DELETED
@@ -1,342 +0,0 @@
1
- /*
2
- colors.js
3
-
4
- Copyright (c) 2010
5
-
6
- Marak Squires
7
- Alexis Sellier (cloudhead)
8
-
9
- Permission is hereby granted, free of charge, to any person obtaining a copy
10
- of this software and associated documentation files (the "Software"), to deal
11
- in the Software without restriction, including without limitation the rights
12
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
- copies of the Software, and to permit persons to whom the Software is
14
- furnished to do so, subject to the following conditions:
15
-
16
- The above copyright notice and this permission notice shall be included in
17
- all copies or substantial portions of the Software.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
- THE SOFTWARE.
26
-
27
- */
28
-
29
- var isHeadless = false;
30
-
31
- if (typeof module !== 'undefined') {
32
- isHeadless = true;
33
- }
34
-
35
- if (!isHeadless) {
36
- var exports = {};
37
- var module = {};
38
- var colors = exports;
39
- exports.mode = "browser";
40
- } else {
41
- exports.mode = "console";
42
- }
43
-
44
- //
45
- // Prototypes the string object to have additional method calls that add terminal colors
46
- //
47
- var addProperty = function (color, func) {
48
- exports[color] = function (str) {
49
- return func.apply(str);
50
- };
51
- String.prototype.__defineGetter__(color, func);
52
- };
53
-
54
- function stylize(str, style) {
55
-
56
- var styles;
57
-
58
- if (exports.mode === 'console') {
59
- styles = {
60
- //styles
61
- 'bold' : ['\x1B[1m', '\x1B[22m'],
62
- 'italic' : ['\x1B[3m', '\x1B[23m'],
63
- 'underline' : ['\x1B[4m', '\x1B[24m'],
64
- 'inverse' : ['\x1B[7m', '\x1B[27m'],
65
- 'strikethrough' : ['\x1B[9m', '\x1B[29m'],
66
- //text colors
67
- //grayscale
68
- 'white' : ['\x1B[37m', '\x1B[39m'],
69
- 'grey' : ['\x1B[90m', '\x1B[39m'],
70
- 'black' : ['\x1B[30m', '\x1B[39m'],
71
- //colors
72
- 'blue' : ['\x1B[34m', '\x1B[39m'],
73
- 'cyan' : ['\x1B[36m', '\x1B[39m'],
74
- 'green' : ['\x1B[32m', '\x1B[39m'],
75
- 'magenta' : ['\x1B[35m', '\x1B[39m'],
76
- 'red' : ['\x1B[31m', '\x1B[39m'],
77
- 'yellow' : ['\x1B[33m', '\x1B[39m'],
78
- //background colors
79
- //grayscale
80
- 'whiteBG' : ['\x1B[47m', '\x1B[49m'],
81
- 'greyBG' : ['\x1B[49;5;8m', '\x1B[49m'],
82
- 'blackBG' : ['\x1B[40m', '\x1B[49m'],
83
- //colors
84
- 'blueBG' : ['\x1B[44m', '\x1B[49m'],
85
- 'cyanBG' : ['\x1B[46m', '\x1B[49m'],
86
- 'greenBG' : ['\x1B[42m', '\x1B[49m'],
87
- 'magentaBG' : ['\x1B[45m', '\x1B[49m'],
88
- 'redBG' : ['\x1B[41m', '\x1B[49m'],
89
- 'yellowBG' : ['\x1B[43m', '\x1B[49m']
90
- };
91
- } else if (exports.mode === 'browser') {
92
- styles = {
93
- //styles
94
- 'bold' : ['<b>', '</b>'],
95
- 'italic' : ['<i>', '</i>'],
96
- 'underline' : ['<u>', '</u>'],
97
- 'inverse' : ['<span style="background-color:black;color:white;">', '</span>'],
98
- 'strikethrough' : ['<del>', '</del>'],
99
- //text colors
100
- //grayscale
101
- 'white' : ['<span style="color:white;">', '</span>'],
102
- 'grey' : ['<span style="color:gray;">', '</span>'],
103
- 'black' : ['<span style="color:black;">', '</span>'],
104
- //colors
105
- 'blue' : ['<span style="color:blue;">', '</span>'],
106
- 'cyan' : ['<span style="color:cyan;">', '</span>'],
107
- 'green' : ['<span style="color:green;">', '</span>'],
108
- 'magenta' : ['<span style="color:magenta;">', '</span>'],
109
- 'red' : ['<span style="color:red;">', '</span>'],
110
- 'yellow' : ['<span style="color:yellow;">', '</span>'],
111
- //background colors
112
- //grayscale
113
- 'whiteBG' : ['<span style="background-color:white;">', '</span>'],
114
- 'greyBG' : ['<span style="background-color:gray;">', '</span>'],
115
- 'blackBG' : ['<span style="background-color:black;">', '</span>'],
116
- //colors
117
- 'blueBG' : ['<span style="background-color:blue;">', '</span>'],
118
- 'cyanBG' : ['<span style="background-color:cyan;">', '</span>'],
119
- 'greenBG' : ['<span style="background-color:green;">', '</span>'],
120
- 'magentaBG' : ['<span style="background-color:magenta;">', '</span>'],
121
- 'redBG' : ['<span style="background-color:red;">', '</span>'],
122
- 'yellowBG' : ['<span style="background-color:yellow;">', '</span>']
123
- };
124
- } else if (exports.mode === 'none') {
125
- return str + '';
126
- } else {
127
- console.log('unsupported mode, try "browser", "console" or "none"');
128
- }
129
- return styles[style][0] + str + styles[style][1];
130
- }
131
-
132
- function applyTheme(theme) {
133
-
134
- //
135
- // Remark: This is a list of methods that exist
136
- // on String that you should not overwrite.
137
- //
138
- var stringPrototypeBlacklist = [
139
- '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor',
140
- 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf', 'charCodeAt',
141
- 'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match', 'replace', 'search', 'slice', 'split', 'substring',
142
- 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight'
143
- ];
144
-
145
- Object.keys(theme).forEach(function (prop) {
146
- if (stringPrototypeBlacklist.indexOf(prop) !== -1) {
147
- console.log('warn: '.red + ('String.prototype' + prop).magenta + ' is probably something you don\'t want to override. Ignoring style name');
148
- }
149
- else {
150
- if (typeof(theme[prop]) === 'string') {
151
- addProperty(prop, function () {
152
- return exports[theme[prop]](this);
153
- });
154
- }
155
- else {
156
- addProperty(prop, function () {
157
- var ret = this;
158
- for (var t = 0; t < theme[prop].length; t++) {
159
- ret = exports[theme[prop][t]](ret);
160
- }
161
- return ret;
162
- });
163
- }
164
- }
165
- });
166
- }
167
-
168
-
169
- //
170
- // Iterate through all default styles and colors
171
- //
172
- var x = ['bold', 'underline', 'strikethrough', 'italic', 'inverse', 'grey', 'black', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta', 'greyBG', 'blackBG', 'yellowBG', 'redBG', 'greenBG', 'blueBG', 'whiteBG', 'cyanBG', 'magentaBG'];
173
- x.forEach(function (style) {
174
-
175
- // __defineGetter__ at the least works in more browsers
176
- // http://robertnyman.com/javascript/javascript-getters-setters.html
177
- // Object.defineProperty only works in Chrome
178
- addProperty(style, function () {
179
- return stylize(this, style);
180
- });
181
- });
182
-
183
- function sequencer(map) {
184
- return function () {
185
- if (!isHeadless) {
186
- return this.replace(/( )/, '$1');
187
- }
188
- var exploded = this.split(""), i = 0;
189
- exploded = exploded.map(map);
190
- return exploded.join("");
191
- };
192
- }
193
-
194
- var rainbowMap = (function () {
195
- var rainbowColors = ['red', 'yellow', 'green', 'blue', 'magenta']; //RoY G BiV
196
- return function (letter, i, exploded) {
197
- if (letter === " ") {
198
- return letter;
199
- } else {
200
- return stylize(letter, rainbowColors[i++ % rainbowColors.length]);
201
- }
202
- };
203
- })();
204
-
205
- exports.themes = {};
206
-
207
- exports.addSequencer = function (name, map) {
208
- addProperty(name, sequencer(map));
209
- };
210
-
211
- exports.addSequencer('rainbow', rainbowMap);
212
- exports.addSequencer('zebra', function (letter, i, exploded) {
213
- return i % 2 === 0 ? letter : letter.inverse;
214
- });
215
-
216
- exports.setTheme = function (theme) {
217
- if (typeof theme === 'string') {
218
- try {
219
- exports.themes[theme] = require(theme);
220
- applyTheme(exports.themes[theme]);
221
- return exports.themes[theme];
222
- } catch (err) {
223
- console.log(err);
224
- return err;
225
- }
226
- } else {
227
- applyTheme(theme);
228
- }
229
- };
230
-
231
-
232
- addProperty('stripColors', function () {
233
- return ("" + this).replace(/\x1B\[\d+m/g, '');
234
- });
235
-
236
- // please no
237
- function zalgo(text, options) {
238
- var soul = {
239
- "up" : [
240
- '̍', '̎', '̄', '̅',
241
- '̿', '̑', '̆', '̐',
242
- '͒', '͗', '͑', '̇',
243
- '̈', '̊', '͂', '̓',
244
- '̈', '͊', '͋', '͌',
245
- '̃', '̂', '̌', '͐',
246
- '̀', '́', '̋', '̏',
247
- '̒', '̓', '̔', '̽',
248
- '̉', 'ͣ', 'ͤ', 'ͥ',
249
- 'ͦ', 'ͧ', 'ͨ', 'ͩ',
250
- 'ͪ', 'ͫ', 'ͬ', 'ͭ',
251
- 'ͮ', 'ͯ', '̾', '͛',
252
- '͆', '̚'
253
- ],
254
- "down" : [
255
- '̖', '̗', '̘', '̙',
256
- '̜', '̝', '̞', '̟',
257
- '̠', '̤', '̥', '̦',
258
- '̩', '̪', '̫', '̬',
259
- '̭', '̮', '̯', '̰',
260
- '̱', '̲', '̳', '̹',
261
- '̺', '̻', '̼', 'ͅ',
262
- '͇', '͈', '͉', '͍',
263
- '͎', '͓', '͔', '͕',
264
- '͖', '͙', '͚', '̣'
265
- ],
266
- "mid" : [
267
- '̕', '̛', '̀', '́',
268
- '͘', '̡', '̢', '̧',
269
- '̨', '̴', '̵', '̶',
270
- '͜', '͝', '͞',
271
- '͟', '͠', '͢', '̸',
272
- '̷', '͡', ' ҉'
273
- ]
274
- },
275
- all = [].concat(soul.up, soul.down, soul.mid),
276
- zalgo = {};
277
-
278
- function randomNumber(range) {
279
- var r = Math.floor(Math.random() * range);
280
- return r;
281
- }
282
-
283
- function is_char(character) {
284
- var bool = false;
285
- all.filter(function (i) {
286
- bool = (i === character);
287
- });
288
- return bool;
289
- }
290
-
291
- function heComes(text, options) {
292
- var result = '', counts, l;
293
- options = options || {};
294
- options["up"] = options["up"] || true;
295
- options["mid"] = options["mid"] || true;
296
- options["down"] = options["down"] || true;
297
- options["size"] = options["size"] || "maxi";
298
- text = text.split('');
299
- for (l in text) {
300
- if (is_char(l)) {
301
- continue;
302
- }
303
- result = result + text[l];
304
- counts = {"up" : 0, "down" : 0, "mid" : 0};
305
- switch (options.size) {
306
- case 'mini':
307
- counts.up = randomNumber(8);
308
- counts.min = randomNumber(2);
309
- counts.down = randomNumber(8);
310
- break;
311
- case 'maxi':
312
- counts.up = randomNumber(16) + 3;
313
- counts.min = randomNumber(4) + 1;
314
- counts.down = randomNumber(64) + 3;
315
- break;
316
- default:
317
- counts.up = randomNumber(8) + 1;
318
- counts.mid = randomNumber(6) / 2;
319
- counts.down = randomNumber(8) + 1;
320
- break;
321
- }
322
-
323
- var arr = ["up", "mid", "down"];
324
- for (var d in arr) {
325
- var index = arr[d];
326
- for (var i = 0 ; i <= counts[index]; i++) {
327
- if (options[index]) {
328
- result = result + soul[index][randomNumber(soul[index].length)];
329
- }
330
- }
331
- }
332
- }
333
- return result;
334
- }
335
- return heComes(text);
336
- }
337
-
338
-
339
- // don't summon zalgo
340
- addProperty('zalgo', function () {
341
- return zalgo(this);
342
- });
package/example.html DELETED
@@ -1,76 +0,0 @@
1
- <!DOCTYPE HTML>
2
- <html lang="en-us">
3
- <head>
4
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5
- <title>Colors Example</title>
6
- <script src="colors.js"></script>
7
- </head>
8
- <body>
9
- <script>
10
-
11
- var test = colors.red("hopefully colorless output");
12
-
13
- document.write('Rainbows are fun!'.rainbow + '<br/>');
14
- document.write('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported
15
- document.write('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
16
- //document.write('zalgo time!'.zalgo);
17
- document.write(test.stripColors);
18
- document.write("a".grey + " b".black);
19
-
20
- document.write("Zebras are so fun!".zebra);
21
-
22
- document.write(colors.rainbow('Rainbows are fun!'));
23
- document.write("This is " + "not".strikethrough + " fun.");
24
-
25
- document.write(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported
26
- document.write(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported
27
- //document.write(colors.zalgo('zalgo time!'));
28
- document.write(colors.stripColors(test));
29
- document.write(colors.grey("a") + colors.black(" b"));
30
-
31
- colors.addSequencer("america", function(letter, i, exploded) {
32
- if(letter === " ") return letter;
33
- switch(i%3) {
34
- case 0: return letter.red;
35
- case 1: return letter.white;
36
- case 2: return letter.blue;
37
- }
38
- });
39
-
40
- colors.addSequencer("random", (function() {
41
- var available = ['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'];
42
-
43
- return function(letter, i, exploded) {
44
- return letter === " " ? letter : letter[available[Math.round(Math.random() * (available.length - 1))]];
45
- };
46
- })());
47
-
48
- document.write("AMERICA! F--K YEAH!".america);
49
- document.write("So apparently I've been to Mars, with all the little green men. But you know, I don't recall.".random);
50
-
51
- //
52
- // Custom themes
53
- //
54
-
55
- colors.setTheme({
56
- silly: 'rainbow',
57
- input: 'grey',
58
- verbose: 'cyan',
59
- prompt: 'grey',
60
- info: 'green',
61
- data: 'grey',
62
- help: 'cyan',
63
- warn: 'yellow',
64
- debug: 'blue',
65
- error: 'red'
66
- });
67
-
68
- // outputs red text
69
- document.write("this is an error".error);
70
-
71
- // outputs yellow text
72
- document.write("this is a warning".warn);
73
-
74
- </script>
75
- </body>
76
- </html>
package/example.js DELETED
@@ -1,77 +0,0 @@
1
- var colors = require('./colors');
2
-
3
- //colors.mode = "browser";
4
-
5
- var test = colors.red("hopefully colorless output");
6
- console.log('Rainbows are fun!'.rainbow);
7
- console.log('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported
8
- console.log('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
9
- //console.log('zalgo time!'.zalgo);
10
- console.log(test.stripColors);
11
- console.log("a".grey + " b".black);
12
- console.log("Zebras are so fun!".zebra);
13
- console.log('background color attack!'.black.whiteBG)
14
-
15
- //
16
- // Remark: .strikethrough may not work with Mac OS Terminal App
17
- //
18
- console.log("This is " + "not".strikethrough + " fun.");
19
- console.log(colors.rainbow('Rainbows are fun!'));
20
- console.log(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported
21
- console.log(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported
22
- //console.log(colors.zalgo('zalgo time!'));
23
- console.log(colors.stripColors(test));
24
- console.log(colors.grey("a") + colors.black(" b"));
25
-
26
- colors.addSequencer("america", function(letter, i, exploded) {
27
- if(letter === " ") return letter;
28
- switch(i%3) {
29
- case 0: return letter.red;
30
- case 1: return letter.white;
31
- case 2: return letter.blue;
32
- }
33
- });
34
-
35
- colors.addSequencer("random", (function() {
36
- var available = ['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'];
37
-
38
- return function(letter, i, exploded) {
39
- return letter === " " ? letter : letter[available[Math.round(Math.random() * (available.length - 1))]];
40
- };
41
- })());
42
-
43
- console.log("AMERICA! F--K YEAH!".america);
44
- console.log("So apparently I've been to Mars, with all the little green men. But you know, I don't recall.".random);
45
-
46
- //
47
- // Custom themes
48
- //
49
-
50
- // Load theme with JSON literal
51
- colors.setTheme({
52
- silly: 'rainbow',
53
- input: 'grey',
54
- verbose: 'cyan',
55
- prompt: 'grey',
56
- info: 'green',
57
- data: 'grey',
58
- help: 'cyan',
59
- warn: 'yellow',
60
- debug: 'blue',
61
- error: 'red'
62
- });
63
-
64
- // outputs red text
65
- console.log("this is an error".error);
66
-
67
- // outputs yellow text
68
- console.log("this is a warning".warn);
69
-
70
- // outputs grey text
71
- console.log("this is an input".input);
72
-
73
- // Load a theme from file
74
- colors.setTheme('./themes/winston-dark.js');
75
-
76
- console.log("this is an input".input);
77
-
@@ -1,12 +0,0 @@
1
- module['exports'] = {
2
- silly: 'rainbow',
3
- input: 'black',
4
- verbose: 'cyan',
5
- prompt: 'grey',
6
- info: 'green',
7
- data: 'grey',
8
- help: 'cyan',
9
- warn: 'yellow',
10
- debug: 'blue',
11
- error: 'red'
12
- };