colors 1.0.2 → 1.1.2

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.
File without changes
package/ReadMe.md CHANGED
@@ -1,8 +1,8 @@
1
- # colors.js
1
+ # colors.js [![Build Status](https://travis-ci.org/Marak/colors.js.svg?branch=master)](https://travis-ci.org/Marak/colors.js)
2
2
 
3
3
  ## get color and style in your node.js console
4
4
 
5
- <img src="https://github.com/Marak/colors.js/raw/master/screenshots/colors.png"/>
5
+ ![Demo](https://raw.githubusercontent.com/Marak/colors.js/master/screenshots/colors.png)
6
6
 
7
7
  ## Installation
8
8
 
@@ -25,8 +25,6 @@
25
25
 
26
26
  ### background colors
27
27
 
28
-
29
-
30
28
  - bgBlack
31
29
  - bgRed
32
30
  - bgGreen
@@ -162,6 +160,19 @@ console.log(colors.error("this is an error"));
162
160
 
163
161
  // outputs yellow text
164
162
  console.log(colors.warn("this is a warning"));
163
+
164
+ ```
165
+
166
+ You can also combine them:
167
+
168
+ ```javascript
169
+ var colors = require('colors');
170
+
171
+ colors.setTheme({
172
+ custom: ['red', 'underline']
173
+ });
174
+
175
+ console.log('test'.custom);
165
176
  ```
166
177
 
167
- *Protip: There is a secret undocumented style in `colors`. If you find the style you can summon him.*
178
+ *Protip: There is a secret undocumented style in `colors`. If you find the style you can summon him.*
package/lib/colors.js CHANGED
@@ -42,11 +42,16 @@ if (typeof colors.enabled === "undefined") {
42
42
  colors.enabled = colors.supportsColor;
43
43
  }
44
44
 
45
- colors.strip = function(str){
45
+ colors.stripColors = colors.strip = function(str){
46
46
  return ("" + str).replace(/\x1B\[\d+m/g, '');
47
47
  };
48
48
 
49
+
49
50
  var stylize = colors.stylize = function stylize (str, style) {
51
+ if (!colors.enabled) {
52
+ return str+'';
53
+ }
54
+
50
55
  return ansiStyles[style].open + str + ansiStyles[style].close;
51
56
  }
52
57
 
@@ -114,6 +119,13 @@ function applyTheme (theme) {
114
119
  for (var style in theme) {
115
120
  (function(style){
116
121
  colors[style] = function(str){
122
+ if (typeof theme[style] === 'object'){
123
+ var out = str;
124
+ for (var i in theme[style]){
125
+ out = colors[theme[style][i]](out);
126
+ }
127
+ return out;
128
+ }
117
129
  return colors[theme[style]](str);
118
130
  };
119
131
  })(style)
@@ -58,10 +58,10 @@ module['exports'] = function zalgo(text, options) {
58
58
  function heComes(text, options) {
59
59
  var result = '', counts, l;
60
60
  options = options || {};
61
- options["up"] = options["up"] || true;
62
- options["mid"] = options["mid"] || true;
63
- options["down"] = options["down"] || true;
64
- options["size"] = options["size"] || "maxi";
61
+ options["up"] = typeof options["up"] !== 'undefined' ? options["up"] : true;
62
+ options["mid"] = typeof options["mid"] !== 'undefined' ? options["mid"] : true;
63
+ options["down"] = typeof options["down"] !== 'undefined' ? options["down"] : true;
64
+ options["size"] = typeof options["size"] !== 'undefined' ? options["size"] : "maxi";
65
65
  text = text.split('');
66
66
  for (l in text) {
67
67
  if (is_char(l)) {
@@ -72,12 +72,12 @@ module['exports'] = function zalgo(text, options) {
72
72
  switch (options.size) {
73
73
  case 'mini':
74
74
  counts.up = randomNumber(8);
75
- counts.min = randomNumber(2);
75
+ counts.mid = randomNumber(2);
76
76
  counts.down = randomNumber(8);
77
77
  break;
78
78
  case 'maxi':
79
79
  counts.up = randomNumber(16) + 3;
80
- counts.min = randomNumber(4) + 1;
80
+ counts.mid = randomNumber(4) + 1;
81
81
  counts.down = randomNumber(64) + 3;
82
82
  break;
83
83
  default:
@@ -100,5 +100,5 @@ module['exports'] = function zalgo(text, options) {
100
100
  return result;
101
101
  }
102
102
  // don't summon him
103
- return heComes(text);
103
+ return heComes(text, options);
104
104
  }
@@ -1,5 +1,4 @@
1
- var colors = require('./colors'),
2
- styles = require('./styles');
1
+ var colors = require('./colors');
3
2
 
4
3
  module['exports'] = function () {
5
4
 
@@ -18,14 +17,14 @@ module['exports'] = function () {
18
17
  }
19
18
  };
20
19
 
21
- var stylize = function stylize (str, style) {
22
- return styles[style].open + str + styles[style].close;
23
- }
24
-
25
20
  addProperty('strip', function () {
26
21
  return colors.strip(this);
27
22
  });
28
23
 
24
+ addProperty('stripColors', function () {
25
+ return colors.strip(this);
26
+ });
27
+
29
28
  addProperty("trap", function(){
30
29
  return colors.trap(this);
31
30
  });
@@ -56,7 +55,7 @@ module['exports'] = function () {
56
55
  var x = Object.keys(colors.styles);
57
56
  x.forEach(function (style) {
58
57
  addProperty(style, function () {
59
- return stylize(this, style);
58
+ return colors.stylize(this, style);
60
59
  });
61
60
  });
62
61
 
@@ -87,7 +86,7 @@ module['exports'] = function () {
87
86
  addProperty(prop, function () {
88
87
  var ret = this;
89
88
  for (var t = 0; t < theme[prop].length; t++) {
90
- ret = exports[theme[prop][t]](ret);
89
+ ret = colors[theme[prop][t]](ret);
91
90
  }
92
91
  return ret;
93
92
  });
package/lib/index.js CHANGED
@@ -9,4 +9,4 @@ module['exports'] = colors;
9
9
  // colors.red("foo")
10
10
  //
11
11
  //
12
- var extendStringPrototype = require('./extendStringPrototype')();
12
+ require('./extendStringPrototype')();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "colors",
3
3
  "description": "get colors in your node.js console",
4
- "version": "1.0.2",
4
+ "version": "1.1.2",
5
5
  "author": "Marak Squires",
6
6
  "homepage": "https://github.com/Marak/colors.js",
7
7
  "bugs": "https://github.com/Marak/colors.js/issues",
@@ -17,5 +17,12 @@
17
17
  "engines": {
18
18
  "node": ">=0.1.90"
19
19
  },
20
- "main": "./lib/index"
20
+ "main": "lib",
21
+ "files": [
22
+ "examples",
23
+ "lib",
24
+ "LICENSE",
25
+ "safe.js",
26
+ "themes"
27
+ ]
21
28
  }
package/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "0.11"
4
- - "0.10"
5
- - "0.8"
6
- - "0.6"
Binary file
@@ -1,50 +0,0 @@
1
- var assert = require('assert'),
2
- colors = require('../lib/index');
3
-
4
- var s = 'string';
5
-
6
- function a(s, code) {
7
- return '\x1B[' + code.toString() + 'm' + s + '\x1B[39m';
8
- }
9
-
10
- function aE(s, color, code) {
11
- assert.equal(s[color], a(s, code));
12
- assert.equal(colors[color](s), a(s, code));
13
- assert.equal(s[color], colors[color](s));
14
- assert.equal(s[color].strip, s);
15
- assert.equal(s[color].strip, colors.strip(s));
16
- }
17
-
18
- function h(s, color) {
19
- return '<span style="color:' + color + ';">' + s + '</span>';
20
- }
21
-
22
- var stylesColors = ['white', 'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow'];
23
- var stylesAll = stylesColors.concat(['bold', 'italic', 'underline', 'inverse', 'rainbow']);
24
-
25
- colors.mode = 'console';
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');
31
-
32
- assert.ok(s.rainbow);
33
-
34
- aE(s, 'white', 37);
35
- aE(s, 'grey', 90);
36
- aE(s, 'black', 30);
37
- aE(s, 'blue', 34);
38
- aE(s, 'cyan', 36);
39
- aE(s, 'green', 32);
40
- aE(s, 'magenta', 35);
41
- aE(s, 'red', 31);
42
- aE(s, 'yellow', 33);
43
-
44
- assert.equal(s, 'string');
45
-
46
- colors.setTheme({error:'red'});
47
-
48
- assert.equal(typeof("astring".red),'string');
49
- assert.equal(typeof("astring".error),'string');
50
-
@@ -1,45 +0,0 @@
1
- var assert = require('assert'),
2
- colors = require('../safe');
3
-
4
- var s = 'string';
5
-
6
- function a(s, code) {
7
- return '\x1B[' + code.toString() + 'm' + s + '\x1B[39m';
8
- }
9
-
10
- function aE(s, color, code) {
11
- assert.equal(colors[color](s), a(s, code));
12
- assert.equal(colors.strip(s), s);
13
- }
14
-
15
- function h(s, color) {
16
- return '<span style="color:' + color + ';">' + s + '</span>';
17
- }
18
-
19
- var stylesColors = ['white', 'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow'];
20
- var stylesAll = stylesColors.concat(['bold', 'italic', 'underline', 'inverse', 'rainbow']);
21
-
22
- colors.mode = 'console';
23
- assert.equal(colors.bold(s), '\x1B[1m' + s + '\x1B[22m');
24
- assert.equal(colors.italic(s), '\x1B[3m' + s + '\x1B[23m');
25
- assert.equal(colors.underline(s), '\x1B[4m' + s + '\x1B[24m');
26
- assert.equal(colors.strikethrough(s), '\x1B[9m' + s + '\x1B[29m');
27
- assert.equal(colors.inverse(s), '\x1B[7m' + s + '\x1B[27m');
28
-
29
- assert.ok(colors.rainbow);
30
-
31
- aE(s, 'white', 37);
32
- aE(s, 'grey', 90);
33
- aE(s, 'black', 30);
34
- aE(s, 'blue', 34);
35
- aE(s, 'cyan', 36);
36
- aE(s, 'green', 32);
37
- aE(s, 'magenta', 35);
38
- aE(s, 'red', 31);
39
- aE(s, 'yellow', 33);
40
-
41
- assert.equal(s, 'string');
42
- colors.setTheme({error:'red'});
43
-
44
- assert.equal(typeof(colors.red("astring")), 'string');
45
- assert.equal(typeof(colors.error("astring")), 'string');