colors 0.6.0 → 0.6.1
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/ReadMe.md +1 -1
- package/colors.js +231 -150
- package/example.html +2 -0
- package/example.js +13 -1
- package/package.json +4 -1
- package/test.js +18 -13
- package/themes/winston-dark.js +12 -0
- package/themes/winston-light.js +12 -0
package/ReadMe.md
CHANGED
package/colors.js
CHANGED
@@ -45,21 +45,142 @@ if (!isHeadless) {
|
|
45
45
|
// Prototypes the string object to have additional method calls that add terminal colors
|
46
46
|
//
|
47
47
|
var addProperty = function (color, func) {
|
48
|
-
|
49
|
-
if (""[color] && allowOverride.indexOf(color) === -1) {
|
50
|
-
throw new Error(color + ' already exists on String.prototype, cannot override.')
|
51
|
-
}
|
52
|
-
exports[color] = function(str) {
|
48
|
+
exports[color] = function (str) {
|
53
49
|
return func.apply(str);
|
54
50
|
};
|
55
|
-
|
51
|
+
|
52
|
+
if (Object.defineProperty) {
|
53
|
+
Object.defineProperty(String.prototype, color, {
|
54
|
+
get : func,
|
55
|
+
configurable: true,
|
56
|
+
enumerable: false
|
57
|
+
});
|
58
|
+
} else {
|
59
|
+
String.prototype.__defineGetter__(color, func);
|
60
|
+
}
|
61
|
+
};
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
function stylize(str, style) {
|
66
|
+
|
67
|
+
var styles;
|
68
|
+
|
69
|
+
if (exports.mode === 'console') {
|
70
|
+
styles = {
|
71
|
+
//styles
|
72
|
+
'bold' : ['\x1B[1m', '\x1B[22m'],
|
73
|
+
'italic' : ['\x1B[3m', '\x1B[23m'],
|
74
|
+
'underline' : ['\x1B[4m', '\x1B[24m'],
|
75
|
+
'inverse' : ['\x1B[7m', '\x1B[27m'],
|
76
|
+
'strikethrough' : ['\x1B[9m', '\x1B[29m'],
|
77
|
+
//text colors
|
78
|
+
//grayscale
|
79
|
+
'white' : ['\x1B[37m', '\x1B[39m'],
|
80
|
+
'grey' : ['\x1B[90m', '\x1B[39m'],
|
81
|
+
'black' : ['\x1B[30m', '\x1B[39m'],
|
82
|
+
//colors
|
83
|
+
'blue' : ['\x1B[34m', '\x1B[39m'],
|
84
|
+
'cyan' : ['\x1B[36m', '\x1B[39m'],
|
85
|
+
'green' : ['\x1B[32m', '\x1B[39m'],
|
86
|
+
'magenta' : ['\x1B[35m', '\x1B[39m'],
|
87
|
+
'red' : ['\x1B[31m', '\x1B[39m'],
|
88
|
+
'yellow' : ['\x1B[33m', '\x1B[39m'],
|
89
|
+
//background colors
|
90
|
+
//grayscale
|
91
|
+
'whiteBG' : ['\x1B[47m', '\x1B[49m'],
|
92
|
+
'greyBG' : ['\x1B[49;5;8m', '\x1B[49m'],
|
93
|
+
'blackBG' : ['\x1B[40m', '\x1B[49m'],
|
94
|
+
//colors
|
95
|
+
'blueBG' : ['\x1B[44m', '\x1B[49m'],
|
96
|
+
'cyanBG' : ['\x1B[46m', '\x1B[49m'],
|
97
|
+
'greenBG' : ['\x1B[42m', '\x1B[49m'],
|
98
|
+
'magentaBG' : ['\x1B[45m', '\x1B[49m'],
|
99
|
+
'redBG' : ['\x1B[41m', '\x1B[49m'],
|
100
|
+
'yellowBG' : ['\x1B[43m', '\x1B[49m']
|
101
|
+
};
|
102
|
+
} else if (exports.mode === 'browser') {
|
103
|
+
styles = {
|
104
|
+
//styles
|
105
|
+
'bold' : ['<b>', '</b>'],
|
106
|
+
'italic' : ['<i>', '</i>'],
|
107
|
+
'underline' : ['<u>', '</u>'],
|
108
|
+
'inverse' : ['<span style="background-color:black;color:white;">', '</span>'],
|
109
|
+
'strikethrough' : ['<del>', '</del>'],
|
110
|
+
//text colors
|
111
|
+
//grayscale
|
112
|
+
'white' : ['<span style="color:white;">', '</span>'],
|
113
|
+
'grey' : ['<span style="color:gray;">', '</span>'],
|
114
|
+
'black' : ['<span style="color:black;">', '</span>'],
|
115
|
+
//colors
|
116
|
+
'blue' : ['<span style="color:blue;">', '</span>'],
|
117
|
+
'cyan' : ['<span style="color:cyan;">', '</span>'],
|
118
|
+
'green' : ['<span style="color:green;">', '</span>'],
|
119
|
+
'magenta' : ['<span style="color:magenta;">', '</span>'],
|
120
|
+
'red' : ['<span style="color:red;">', '</span>'],
|
121
|
+
'yellow' : ['<span style="color:yellow;">', '</span>'],
|
122
|
+
//background colors
|
123
|
+
//grayscale
|
124
|
+
'whiteBG' : ['<span style="background-color:white;">', '</span>'],
|
125
|
+
'greyBG' : ['<span style="background-color:gray;">', '</span>'],
|
126
|
+
'blackBG' : ['<span style="background-color:black;">', '</span>'],
|
127
|
+
//colors
|
128
|
+
'blueBG' : ['<span style="background-color:blue;">', '</span>'],
|
129
|
+
'cyanBG' : ['<span style="background-color:cyan;">', '</span>'],
|
130
|
+
'greenBG' : ['<span style="background-color:green;">', '</span>'],
|
131
|
+
'magentaBG' : ['<span style="background-color:magenta;">', '</span>'],
|
132
|
+
'redBG' : ['<span style="background-color:red;">', '</span>'],
|
133
|
+
'yellowBG' : ['<span style="background-color:yellow;">', '</span>']
|
134
|
+
};
|
135
|
+
} else if (exports.mode === 'none') {
|
136
|
+
return str + '';
|
137
|
+
} else {
|
138
|
+
console.log('unsupported mode, try "browser", "console" or "none"');
|
139
|
+
}
|
140
|
+
return styles[style][0] + str + styles[style][1];
|
141
|
+
}
|
142
|
+
|
143
|
+
function applyTheme(theme) {
|
144
|
+
|
145
|
+
//
|
146
|
+
// Remark: This is a list of methods that exist
|
147
|
+
// on String that you should not overwrite.
|
148
|
+
//
|
149
|
+
var stringPrototypeBlacklist = [
|
150
|
+
'__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor',
|
151
|
+
'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf', 'charCodeAt',
|
152
|
+
'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match', 'replace', 'search', 'slice', 'split', 'substring',
|
153
|
+
'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight'
|
154
|
+
];
|
155
|
+
|
156
|
+
Object.keys(theme).forEach(function (prop) {
|
157
|
+
if (stringPrototypeBlacklist.indexOf(prop) !== -1) {
|
158
|
+
console.log('warn: '.red + ('String.prototype' + prop).magenta + ' is probably something you don\'t want to override. Ignoring style name');
|
159
|
+
}
|
160
|
+
else {
|
161
|
+
if (typeof(theme[prop]) === 'string') {
|
162
|
+
addProperty(prop, function () {
|
163
|
+
return exports[theme[prop]](this);
|
164
|
+
});
|
165
|
+
}
|
166
|
+
else {
|
167
|
+
addProperty(prop, function () {
|
168
|
+
var ret = this;
|
169
|
+
for (var t = 0; t < theme[prop].length; t++) {
|
170
|
+
ret = exports[theme[prop][t]](ret);
|
171
|
+
}
|
172
|
+
return ret;
|
173
|
+
});
|
174
|
+
}
|
175
|
+
}
|
176
|
+
});
|
56
177
|
}
|
57
178
|
|
179
|
+
|
58
180
|
//
|
59
181
|
// Iterate through all default styles and colors
|
60
182
|
//
|
61
|
-
|
62
|
-
var x = ['bold', 'underline', 'italic', 'inverse', 'grey', 'black', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'];
|
183
|
+
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'];
|
63
184
|
x.forEach(function (style) {
|
64
185
|
|
65
186
|
// __defineGetter__ at the least works in more browsers
|
@@ -75,27 +196,28 @@ function sequencer(map) {
|
|
75
196
|
if (!isHeadless) {
|
76
197
|
return this.replace(/( )/, '$1');
|
77
198
|
}
|
78
|
-
var exploded = this.split("");
|
79
|
-
var i = 0;
|
199
|
+
var exploded = this.split(""), i = 0;
|
80
200
|
exploded = exploded.map(map);
|
81
201
|
return exploded.join("");
|
82
|
-
}
|
202
|
+
};
|
83
203
|
}
|
84
204
|
|
85
205
|
var rainbowMap = (function () {
|
86
|
-
var rainbowColors = ['red','yellow','green','blue','magenta']; //RoY G BiV
|
206
|
+
var rainbowColors = ['red', 'yellow', 'green', 'blue', 'magenta']; //RoY G BiV
|
87
207
|
return function (letter, i, exploded) {
|
88
|
-
if (letter
|
208
|
+
if (letter === " ") {
|
89
209
|
return letter;
|
90
210
|
} else {
|
91
211
|
return stylize(letter, rainbowColors[i++ % rainbowColors.length]);
|
92
212
|
}
|
93
|
-
}
|
213
|
+
};
|
94
214
|
})();
|
95
215
|
|
216
|
+
exports.themes = {};
|
217
|
+
|
96
218
|
exports.addSequencer = function (name, map) {
|
97
219
|
addProperty(name, sequencer(map));
|
98
|
-
}
|
220
|
+
};
|
99
221
|
|
100
222
|
exports.addSequencer('rainbow', rainbowMap);
|
101
223
|
exports.addSequencer('zebra', function (letter, i, exploded) {
|
@@ -103,170 +225,129 @@ exports.addSequencer('zebra', function (letter, i, exploded) {
|
|
103
225
|
});
|
104
226
|
|
105
227
|
exports.setTheme = function (theme) {
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
if (exports.mode == 'console') {
|
116
|
-
var styles = {
|
117
|
-
//styles
|
118
|
-
'bold' : ['\033[1m', '\033[22m'],
|
119
|
-
'italic' : ['\033[3m', '\033[23m'],
|
120
|
-
'underline' : ['\033[4m', '\033[24m'],
|
121
|
-
'inverse' : ['\033[7m', '\033[27m'],
|
122
|
-
//grayscale
|
123
|
-
'white' : ['\033[37m', '\033[39m'],
|
124
|
-
'grey' : ['\033[90m', '\033[39m'],
|
125
|
-
'black' : ['\033[30m', '\033[39m'],
|
126
|
-
//colors
|
127
|
-
'blue' : ['\033[34m', '\033[39m'],
|
128
|
-
'cyan' : ['\033[36m', '\033[39m'],
|
129
|
-
'green' : ['\033[32m', '\033[39m'],
|
130
|
-
'magenta' : ['\033[35m', '\033[39m'],
|
131
|
-
'red' : ['\033[31m', '\033[39m'],
|
132
|
-
'yellow' : ['\033[33m', '\033[39m']
|
133
|
-
};
|
134
|
-
} else if (exports.mode == 'browser') {
|
135
|
-
var styles = {
|
136
|
-
//styles
|
137
|
-
'bold' : ['<b>', '</b>'],
|
138
|
-
'italic' : ['<i>', '</i>'],
|
139
|
-
'underline' : ['<u>', '</u>'],
|
140
|
-
'inverse' : ['<span style="background-color:black;color:white;">', '</span>'],
|
141
|
-
//grayscale
|
142
|
-
'white' : ['<span style="color:white;">', '</span>'],
|
143
|
-
'grey' : ['<span style="color:grey;">', '</span>'],
|
144
|
-
'black' : ['<span style="color:black;">', '</span>'],
|
145
|
-
//colors
|
146
|
-
'blue' : ['<span style="color:blue;">', '</span>'],
|
147
|
-
'cyan' : ['<span style="color:cyan;">', '</span>'],
|
148
|
-
'green' : ['<span style="color:green;">', '</span>'],
|
149
|
-
'magenta' : ['<span style="color:magenta;">', '</span>'],
|
150
|
-
'red' : ['<span style="color:red;">', '</span>'],
|
151
|
-
'yellow' : ['<span style="color:yellow;">', '</span>']
|
152
|
-
};
|
153
|
-
} else if (exports.mode == 'none') {
|
154
|
-
return str;
|
228
|
+
if (typeof theme === 'string') {
|
229
|
+
try {
|
230
|
+
exports.themes[theme] = require(theme);
|
231
|
+
applyTheme(exports.themes[theme]);
|
232
|
+
return exports.themes[theme];
|
233
|
+
} catch (err) {
|
234
|
+
console.log(err);
|
235
|
+
return err;
|
236
|
+
}
|
155
237
|
} else {
|
156
|
-
|
238
|
+
applyTheme(theme);
|
157
239
|
}
|
158
|
-
return styles[style][0] + str + styles[style][1];
|
159
240
|
};
|
160
241
|
|
161
|
-
|
162
|
-
addProperty('
|
163
|
-
return
|
242
|
+
|
243
|
+
addProperty('stripColors', function () {
|
244
|
+
return ("" + this).replace(/\x1B\[\d+m/g, '');
|
164
245
|
});
|
165
246
|
|
166
247
|
// please no
|
167
248
|
function zalgo(text, options) {
|
168
249
|
var soul = {
|
169
250
|
"up" : [
|
170
|
-
'̍','̎','̄','̅',
|
171
|
-
'̿','̑','̆','̐',
|
172
|
-
'͒','͗','͑','̇',
|
173
|
-
'̈','̊','͂','̓',
|
174
|
-
'̈','͊','͋','͌',
|
175
|
-
'̃','̂','̌','͐',
|
176
|
-
'̀','́','̋','̏',
|
177
|
-
'̒','̓','̔','̽',
|
178
|
-
'̉','ͣ','ͤ','ͥ',
|
179
|
-
'ͦ','ͧ','ͨ','ͩ',
|
180
|
-
'ͪ','ͫ','ͬ','ͭ',
|
181
|
-
'ͮ','ͯ','̾','͛',
|
182
|
-
'͆','̚'
|
183
|
-
|
251
|
+
'̍', '̎', '̄', '̅',
|
252
|
+
'̿', '̑', '̆', '̐',
|
253
|
+
'͒', '͗', '͑', '̇',
|
254
|
+
'̈', '̊', '͂', '̓',
|
255
|
+
'̈', '͊', '͋', '͌',
|
256
|
+
'̃', '̂', '̌', '͐',
|
257
|
+
'̀', '́', '̋', '̏',
|
258
|
+
'̒', '̓', '̔', '̽',
|
259
|
+
'̉', 'ͣ', 'ͤ', 'ͥ',
|
260
|
+
'ͦ', 'ͧ', 'ͨ', 'ͩ',
|
261
|
+
'ͪ', 'ͫ', 'ͬ', 'ͭ',
|
262
|
+
'ͮ', 'ͯ', '̾', '͛',
|
263
|
+
'͆', '̚'
|
264
|
+
],
|
184
265
|
"down" : [
|
185
|
-
'̖','̗','̘','̙',
|
186
|
-
'̜','̝','̞','̟',
|
187
|
-
'̠','̤','̥','̦',
|
188
|
-
'̩','̪','̫','̬',
|
189
|
-
'̭','̮','̯','̰',
|
190
|
-
'̱','̲','̳','̹',
|
191
|
-
'̺','̻','̼','ͅ',
|
192
|
-
'͇','͈','͉','͍',
|
193
|
-
'͎','͓','͔','͕',
|
194
|
-
'͖','͙','͚','̣'
|
195
|
-
|
266
|
+
'̖', '̗', '̘', '̙',
|
267
|
+
'̜', '̝', '̞', '̟',
|
268
|
+
'̠', '̤', '̥', '̦',
|
269
|
+
'̩', '̪', '̫', '̬',
|
270
|
+
'̭', '̮', '̯', '̰',
|
271
|
+
'̱', '̲', '̳', '̹',
|
272
|
+
'̺', '̻', '̼', 'ͅ',
|
273
|
+
'͇', '͈', '͉', '͍',
|
274
|
+
'͎', '͓', '͔', '͕',
|
275
|
+
'͖', '͙', '͚', '̣'
|
276
|
+
],
|
196
277
|
"mid" : [
|
197
|
-
'̕','̛','̀','́',
|
198
|
-
'͘','̡','̢','̧',
|
199
|
-
'̨','̴','̵','̶',
|
200
|
-
'͜','͝','͞',
|
201
|
-
'͟','͠','͢','̸',
|
202
|
-
'̷','͡',' ҉'
|
203
|
-
|
278
|
+
'̕', '̛', '̀', '́',
|
279
|
+
'͘', '̡', '̢', '̧',
|
280
|
+
'̨', '̴', '̵', '̶',
|
281
|
+
'͜', '͝', '͞',
|
282
|
+
'͟', '͠', '͢', '̸',
|
283
|
+
'̷', '͡', ' ҉'
|
284
|
+
]
|
204
285
|
},
|
205
286
|
all = [].concat(soul.up, soul.down, soul.mid),
|
206
287
|
zalgo = {};
|
207
288
|
|
208
289
|
function randomNumber(range) {
|
209
|
-
r = Math.floor(Math.random()*range);
|
290
|
+
var r = Math.floor(Math.random() * range);
|
210
291
|
return r;
|
211
|
-
}
|
292
|
+
}
|
212
293
|
|
213
294
|
function is_char(character) {
|
214
295
|
var bool = false;
|
215
|
-
all.filter(function(i){
|
216
|
-
|
296
|
+
all.filter(function (i) {
|
297
|
+
bool = (i === character);
|
217
298
|
});
|
218
299
|
return bool;
|
219
300
|
}
|
220
301
|
|
221
|
-
function heComes(text, options){
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
}
|
302
|
+
function heComes(text, options) {
|
303
|
+
var result = '', counts, l;
|
304
|
+
options = options || {};
|
305
|
+
options["up"] = options["up"] || true;
|
306
|
+
options["mid"] = options["mid"] || true;
|
307
|
+
options["down"] = options["down"] || true;
|
308
|
+
options["size"] = options["size"] || "maxi";
|
309
|
+
text = text.split('');
|
310
|
+
for (l in text) {
|
311
|
+
if (is_char(l)) {
|
312
|
+
continue;
|
313
|
+
}
|
314
|
+
result = result + text[l];
|
315
|
+
counts = {"up" : 0, "down" : 0, "mid" : 0};
|
316
|
+
switch (options.size) {
|
317
|
+
case 'mini':
|
318
|
+
counts.up = randomNumber(8);
|
319
|
+
counts.min = randomNumber(2);
|
320
|
+
counts.down = randomNumber(8);
|
321
|
+
break;
|
322
|
+
case 'maxi':
|
323
|
+
counts.up = randomNumber(16) + 3;
|
324
|
+
counts.min = randomNumber(4) + 1;
|
325
|
+
counts.down = randomNumber(64) + 3;
|
326
|
+
break;
|
327
|
+
default:
|
328
|
+
counts.up = randomNumber(8) + 1;
|
329
|
+
counts.mid = randomNumber(6) / 2;
|
330
|
+
counts.down = randomNumber(8) + 1;
|
331
|
+
break;
|
332
|
+
}
|
253
333
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
{
|
259
|
-
|
260
|
-
result = result + soul[index][randomNumber(soul[index].length)];
|
261
|
-
}
|
262
|
-
}
|
334
|
+
var arr = ["up", "mid", "down"];
|
335
|
+
for (var d in arr) {
|
336
|
+
var index = arr[d];
|
337
|
+
for (var i = 0 ; i <= counts[index]; i++) {
|
338
|
+
if (options[index]) {
|
339
|
+
result = result + soul[index][randomNumber(soul[index].length)];
|
263
340
|
}
|
264
341
|
}
|
265
|
-
|
266
|
-
|
342
|
+
}
|
343
|
+
}
|
344
|
+
return result;
|
345
|
+
}
|
267
346
|
return heComes(text);
|
268
347
|
}
|
269
348
|
|
270
|
-
|
271
|
-
|
349
|
+
|
350
|
+
// don't summon zalgo
|
351
|
+
addProperty('zalgo', function () {
|
352
|
+
return zalgo(this);
|
272
353
|
});
|
package/example.html
CHANGED
@@ -20,6 +20,8 @@
|
|
20
20
|
document.write("Zebras are so fun!".zebra);
|
21
21
|
|
22
22
|
document.write(colors.rainbow('Rainbows are fun!'));
|
23
|
+
document.write("This is " + "not".strikethrough + " fun.");
|
24
|
+
|
23
25
|
document.write(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported
|
24
26
|
document.write(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported
|
25
27
|
//document.write(colors.zalgo('zalgo time!'));
|
package/example.js
CHANGED
@@ -9,9 +9,13 @@ console.log('Chains are also cool.'.bold.italic.underline.red); // styles not wi
|
|
9
9
|
//console.log('zalgo time!'.zalgo);
|
10
10
|
console.log(test.stripColors);
|
11
11
|
console.log("a".grey + " b".black);
|
12
|
-
|
13
12
|
console.log("Zebras are so fun!".zebra);
|
13
|
+
console.log('background color attack!'.black.whiteBG)
|
14
14
|
|
15
|
+
//
|
16
|
+
// Remark: .strikethrough may not work with Mac OS Terminal App
|
17
|
+
//
|
18
|
+
console.log("This is " + "not".strikethrough + " fun.");
|
15
19
|
console.log(colors.rainbow('Rainbows are fun!'));
|
16
20
|
console.log(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported
|
17
21
|
console.log(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported
|
@@ -43,6 +47,7 @@ console.log("So apparently I've been to Mars, with all the little green men. But
|
|
43
47
|
// Custom themes
|
44
48
|
//
|
45
49
|
|
50
|
+
// Load theme with JSON literal
|
46
51
|
colors.setTheme({
|
47
52
|
silly: 'rainbow',
|
48
53
|
input: 'grey',
|
@@ -62,4 +67,11 @@ console.log("this is an error".error);
|
|
62
67
|
// outputs yellow text
|
63
68
|
console.log("this is a warning".warn);
|
64
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);
|
65
77
|
|
package/package.json
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "colors",
|
3
3
|
"description": "get colors in your node.js console like what",
|
4
|
-
"version": "0.6.
|
4
|
+
"version": "0.6.1",
|
5
5
|
"author": "Marak Squires",
|
6
|
+
"homepage": "https://github.com/Marak/colors.js",
|
7
|
+
"bugs": "https://github.com/Marak/colors.js/issues",
|
8
|
+
"keywords": [ "ansi", "terminal", "colors" ],
|
6
9
|
"repository": {
|
7
10
|
"type": "git",
|
8
11
|
"url": "http://github.com/Marak/colors.js.git"
|
package/test.js
CHANGED
@@ -1,16 +1,10 @@
|
|
1
1
|
var assert = require('assert'),
|
2
2
|
colors = require('./colors');
|
3
3
|
|
4
|
-
//
|
5
|
-
// This is a pretty nice example on how tests shouldn't be written. However,
|
6
|
-
// it's more about API stability than about really testing it (although it's
|
7
|
-
// a pretty complete test suite).
|
8
|
-
//
|
9
|
-
|
10
4
|
var s = 'string';
|
11
5
|
|
12
6
|
function a(s, code) {
|
13
|
-
return '\
|
7
|
+
return '\x1B[' + code.toString() + 'm' + s + '\x1B[39m';
|
14
8
|
}
|
15
9
|
|
16
10
|
function aE(s, color, code) {
|
@@ -23,17 +17,17 @@ function aE(s, color, code) {
|
|
23
17
|
|
24
18
|
function h(s, color) {
|
25
19
|
return '<span style="color:' + color + ';">' + s + '</span>';
|
26
|
-
// that's pretty dumb approach to testing it
|
27
20
|
}
|
28
21
|
|
29
|
-
var stylesColors = ['white', '
|
22
|
+
var stylesColors = ['white', 'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow'];
|
30
23
|
var stylesAll = stylesColors.concat(['bold', 'italic', 'underline', 'inverse', 'rainbow']);
|
31
24
|
|
32
25
|
colors.mode = 'console';
|
33
|
-
assert.equal(s.bold, '\
|
34
|
-
assert.equal(s.italic, '\
|
35
|
-
assert.equal(s.underline, '\
|
36
|
-
assert.equal(s.
|
26
|
+
assert.equal(s.bold, '\x1B[1m' + s + '\x1B[22m');
|
27
|
+
assert.equal(s.italic, '\x1B[3m' + s + '\x1B[23m');
|
28
|
+
assert.equal(s.underline, '\x1B[4m' + s + '\x1B[24m');
|
29
|
+
assert.equal(s.strikethrough, '\x1B[9m' + s + '\x1B[29m');
|
30
|
+
assert.equal(s.inverse, '\x1B[7m' + s + '\x1B[27m');
|
37
31
|
assert.ok(s.rainbow);
|
38
32
|
aE(s, 'white', 37);
|
39
33
|
aE(s, 'grey', 90);
|
@@ -46,10 +40,16 @@ aE(s, 'red', 31);
|
|
46
40
|
aE(s, 'yellow', 33);
|
47
41
|
assert.equal(s, 'string');
|
48
42
|
|
43
|
+
colors.setTheme({error:'red'});
|
44
|
+
|
45
|
+
assert.equal(typeof("astring".red),'string');
|
46
|
+
assert.equal(typeof("astring".error),'string');
|
47
|
+
|
49
48
|
colors.mode = 'browser';
|
50
49
|
assert.equal(s.bold, '<b>' + s + '</b>');
|
51
50
|
assert.equal(s.italic, '<i>' + s + '</i>');
|
52
51
|
assert.equal(s.underline, '<u>' + s + '</u>');
|
52
|
+
assert.equal(s.strikethrough, '<del>' + s + '</del>');
|
53
53
|
assert.equal(s.inverse, '<span style="background-color:black;color:white;">' + s + '</span>');
|
54
54
|
assert.ok(s.rainbow);
|
55
55
|
stylesColors.forEach(function (color) {
|
@@ -57,9 +57,14 @@ stylesColors.forEach(function (color) {
|
|
57
57
|
assert.equal(colors[color](s), h(s, color));
|
58
58
|
});
|
59
59
|
|
60
|
+
assert.equal(typeof("astring".red),'string');
|
61
|
+
assert.equal(typeof("astring".error),'string');
|
62
|
+
|
60
63
|
colors.mode = 'none';
|
61
64
|
stylesAll.forEach(function (style) {
|
62
65
|
assert.equal(s[style], s);
|
63
66
|
assert.equal(colors[style](s), s);
|
64
67
|
});
|
65
68
|
|
69
|
+
assert.equal(typeof("astring".red),'string');
|
70
|
+
assert.equal(typeof("astring".error),'string');
|