colors 1.3.0 → 1.4.0

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 CHANGED
@@ -29,6 +29,16 @@ Please check out the [roadmap](ROADMAP.md) for upcoming features and releases.
29
29
  - gray
30
30
  - grey
31
31
 
32
+ ### bright text colors
33
+
34
+ - brightRed
35
+ - brightGreen
36
+ - brightYellow
37
+ - brightBlue
38
+ - brightMagenta
39
+ - brightCyan
40
+ - brightWhite
41
+
32
42
  ### background colors
33
43
 
34
44
  - bgBlack
@@ -39,6 +49,18 @@ Please check out the [roadmap](ROADMAP.md) for upcoming features and releases.
39
49
  - bgMagenta
40
50
  - bgCyan
41
51
  - bgWhite
52
+ - bgGray
53
+ - bgGrey
54
+
55
+ ### bright background colors
56
+
57
+ - bgBrightRed
58
+ - bgBrightGreen
59
+ - bgBrightYellow
60
+ - bgBrightBlue
61
+ - bgBrightMagenta
62
+ - bgBrightCyan
63
+ - bgBrightWhite
42
64
 
43
65
  ### styles
44
66
 
@@ -94,12 +116,27 @@ I prefer the first way. Some people seem to be afraid of extending `String.proto
94
116
 
95
117
  If you are writing good code you will never have an issue with the first approach. If you really don't want to touch `String.prototype`, the second usage will not touch `String` native object.
96
118
 
97
- ## Disabling Colors
119
+ ## Enabling/Disabling Colors
98
120
 
99
- To disable colors you can pass the following arguments in the command line to your application:
121
+ The package will auto-detect whether your terminal can use colors and enable/disable accordingly. When colors are disabled, the color functions do nothing. You can override this with a command-line flag:
100
122
 
101
123
  ```bash
102
124
  node myapp.js --no-color
125
+ node myapp.js --color=false
126
+
127
+ node myapp.js --color
128
+ node myapp.js --color=true
129
+ node myapp.js --color=always
130
+
131
+ FORCE_COLOR=1 node myapp.js
132
+ ```
133
+
134
+ Or in code:
135
+
136
+ ```javascript
137
+ var colors = require('colors');
138
+ colors.enable();
139
+ colors.disable();
103
140
  ```
104
141
 
105
142
  ## Console.log [string substitution](http://nodejs.org/docs/latest/api/console.html#console_console_log_data)
@@ -29,6 +29,7 @@ console.log('Background color attack!'.black.bgWhite);
29
29
  console.log('Use random styles on everything!'.random);
30
30
  console.log('America, Heck Yeah!'.america);
31
31
 
32
+ console.log('Blindingly '.brightCyan + 'bright? '.brightRed + 'Why '.brightYellow + 'not?!'.brightGreen);
32
33
 
33
34
  console.log('Setting themes is useful');
34
35
 
@@ -28,6 +28,8 @@ console.log(colors.black.bgWhite('Background color attack!'));
28
28
  console.log(colors.random('Use random styles on everything!'));
29
29
  console.log(colors.america('America, Heck Yeah!'));
30
30
 
31
+ console.log(colors.brightCyan('Blindingly ') + colors.brightRed('bright? ') + colors.brightYellow('Why ') + colors.brightGreen('not?!'));
32
+
31
33
  console.log('Setting themes is useful');
32
34
 
33
35
  //
@@ -37,7 +39,7 @@ console.log('Setting themes is useful');
37
39
  // Load theme with JSON literal
38
40
  colors.setTheme({
39
41
  silly: 'rainbow',
40
- input: 'grey',
42
+ input: 'blue',
41
43
  verbose: 'cyan',
42
44
  prompt: 'grey',
43
45
  info: 'green',
@@ -54,14 +56,14 @@ console.log(colors.error('this is an error'));
54
56
  // outputs yellow text
55
57
  console.log(colors.warn('this is a warning'));
56
58
 
57
- // outputs grey text
59
+ // outputs blue text
58
60
  console.log(colors.input('this is an input'));
59
61
 
60
62
 
61
63
  // console.log('Generic logging theme as file'.green.bold.underline);
62
64
 
63
65
  // Load a theme from file
64
- colors.setTheme(__dirname + '/../themes/generic-logging.js');
66
+ colors.setTheme(require(__dirname + '/../themes/generic-logging.js'));
65
67
 
66
68
  // outputs red text
67
69
  console.log(colors.error('this is an error'));
package/index.d.ts CHANGED
@@ -116,8 +116,8 @@ declare global {
116
116
  bgCyan: string;
117
117
  bgWhite: string;
118
118
 
119
- reset: string;
120
- // @ts-ignore
119
+ reset: string;
120
+ // @ts-ignore
121
121
  bold: string;
122
122
  dim: string;
123
123
  italic: string;
package/lib/colors.js CHANGED
@@ -62,7 +62,16 @@ var stylize = colors.stylize = function stylize(str, style) {
62
62
  return str+'';
63
63
  }
64
64
 
65
- return ansiStyles[style].open + str + ansiStyles[style].close;
65
+ var styleMap = ansiStyles[style];
66
+
67
+ // Stylize should work for non-ANSI styles, too
68
+ if(!styleMap && style in colors){
69
+ // Style maps like trap operate as functions on strings;
70
+ // they don't have properties like open or close.
71
+ return colors[style](str);
72
+ }
73
+
74
+ return styleMap.open + str + styleMap.close;
66
75
  };
67
76
 
68
77
  var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
@@ -105,7 +114,8 @@ function applyStyle() {
105
114
  var args = Array.prototype.slice.call(arguments);
106
115
 
107
116
  var str = args.map(function(arg) {
108
- if (arg !== undefined && arg.constructor === String) {
117
+ // Use weak equality check so we can colorize null/undefined in safe mode
118
+ if (arg != null && arg.constructor === String) {
109
119
  return arg;
110
120
  } else {
111
121
  return util.inspect(arg);
@@ -125,7 +135,9 @@ function applyStyle() {
125
135
  var code = ansiStyles[nestedStyles[i]];
126
136
  str = code.open + str.replace(code.closeRe, code.open) + code.close;
127
137
  if (newLinesPresent) {
128
- str = str.replace(newLineRegex, code.close + '\n' + code.open);
138
+ str = str.replace(newLineRegex, function(match) {
139
+ return code.close + match + code.open;
140
+ });
129
141
  }
130
142
  }
131
143
 
@@ -183,10 +195,10 @@ colors.zalgo = require('./custom/zalgo');
183
195
 
184
196
  // maps
185
197
  colors.maps = {};
186
- colors.maps.america = require('./maps/america');
187
- colors.maps.zebra = require('./maps/zebra');
188
- colors.maps.rainbow = require('./maps/rainbow');
189
- colors.maps.random = require('./maps/random');
198
+ colors.maps.america = require('./maps/america')(colors);
199
+ colors.maps.zebra = require('./maps/zebra')(colors);
200
+ colors.maps.rainbow = require('./maps/rainbow')(colors);
201
+ colors.maps.random = require('./maps/random')(colors);
190
202
 
191
203
  for (var map in colors.maps) {
192
204
  (function(map) {
@@ -8,7 +8,7 @@ module['exports'] = function runTheTrap(text, options) {
8
8
  c: ['\u00a9', '\u023b', '\u03fe'],
9
9
  d: ['\u00d0', '\u018a', '\u0500', '\u0501', '\u0502', '\u0503'],
10
10
  e: ['\u00cb', '\u0115', '\u018e', '\u0258', '\u03a3', '\u03be', '\u04bc',
11
- '\u0a6c'],
11
+ '\u0a6c'],
12
12
  f: ['\u04fa'],
13
13
  g: ['\u0262'],
14
14
  h: ['\u0126', '\u0195', '\u04a2', '\u04ba', '\u04c7', '\u050a'],
@@ -19,7 +19,7 @@ module['exports'] = function runTheTrap(text, options) {
19
19
  m: ['\u028d', '\u04cd', '\u04ce', '\u0520', '\u0521', '\u0d69'],
20
20
  n: ['\u00d1', '\u014b', '\u019d', '\u0376', '\u03a0', '\u048a'],
21
21
  o: ['\u00d8', '\u00f5', '\u00f8', '\u01fe', '\u0298', '\u047a', '\u05dd',
22
- '\u06dd', '\u0e4f'],
22
+ '\u06dd', '\u0e4f'],
23
23
  p: ['\u01f7', '\u048e'],
24
24
  q: ['\u09cd'],
25
25
  r: ['\u00ae', '\u01a6', '\u0210', '\u024c', '\u0280', '\u042f'],
@@ -75,21 +75,21 @@ module['exports'] = function zalgo(text, options) {
75
75
  result = result + text[l];
76
76
  counts = {'up': 0, 'down': 0, 'mid': 0};
77
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;
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
93
  }
94
94
 
95
95
  var arr = ['up', 'mid', 'down'];
@@ -74,16 +74,20 @@ module['exports'] = function() {
74
74
  if (typeof(theme[prop]) === 'string') {
75
75
  colors[prop] = colors[theme[prop]];
76
76
  addProperty(prop, function() {
77
- return colors[theme[prop]](this);
77
+ return colors[prop](this);
78
78
  });
79
79
  } else {
80
- addProperty(prop, function() {
81
- var ret = this;
80
+ var themePropApplicator = function(str) {
81
+ var ret = str || this;
82
82
  for (var t = 0; t < theme[prop].length; t++) {
83
83
  ret = colors[theme[prop][t]](ret);
84
84
  }
85
85
  return ret;
86
- });
86
+ };
87
+ addProperty(prop, themePropApplicator);
88
+ colors[prop] = function(str) {
89
+ return themePropApplicator(str);
90
+ };
87
91
  }
88
92
  }
89
93
  });
@@ -98,7 +102,7 @@ module['exports'] = function() {
98
102
  '\'/../themes/generic-logging.js\'); The new syntax looks like '+
99
103
  'colors.setTheme(require(__dirname + ' +
100
104
  '\'/../themes/generic-logging.js\'));');
101
- return;
105
+ return;
102
106
  } else {
103
107
  applyTheme(theme);
104
108
  }
@@ -1,6 +1,4 @@
1
- var colors = require('../colors');
2
-
3
- module['exports'] = (function() {
1
+ module['exports'] = function(colors) {
4
2
  return function(letter, i, exploded) {
5
3
  if (letter === ' ') return letter;
6
4
  switch (i%3) {
@@ -9,4 +7,4 @@ module['exports'] = (function() {
9
7
  case 2: return colors.blue(letter);
10
8
  }
11
9
  };
12
- })();
10
+ };
@@ -1,6 +1,4 @@
1
- var colors = require('../colors');
2
-
3
- module['exports'] = (function() {
1
+ module['exports'] = function(colors) {
4
2
  // RoY G BiV
5
3
  var rainbowColors = ['red', 'yellow', 'green', 'blue', 'magenta'];
6
4
  return function(letter, i, exploded) {
@@ -10,5 +8,5 @@ module['exports'] = (function() {
10
8
  return colors[rainbowColors[i++ % rainbowColors.length]](letter);
11
9
  }
12
10
  };
13
- })();
11
+ };
14
12
 
@@ -1,12 +1,11 @@
1
- var colors = require('../colors');
2
-
3
- module['exports'] = (function() {
1
+ module['exports'] = function(colors) {
4
2
  var available = ['underline', 'inverse', 'grey', 'yellow', 'red', 'green',
5
- 'blue', 'white', 'cyan', 'magenta'];
3
+ 'blue', 'white', 'cyan', 'magenta', 'brightYellow', 'brightRed',
4
+ 'brightGreen', 'brightBlue', 'brightWhite', 'brightCyan', 'brightMagenta'];
6
5
  return function(letter, i, exploded) {
7
6
  return letter === ' ' ? letter :
8
7
  colors[
9
- available[Math.round(Math.random() * (available.length - 2))]
8
+ available[Math.round(Math.random() * (available.length - 2))]
10
9
  ](letter);
11
10
  };
12
- })();
11
+ };
package/lib/maps/zebra.js CHANGED
@@ -1,5 +1,5 @@
1
- var colors = require('../colors');
2
-
3
- module['exports'] = function(letter, i, exploded) {
4
- return i % 2 === 0 ? letter : colors.inverse(letter);
1
+ module['exports'] = function(colors) {
2
+ return function(letter, i, exploded) {
3
+ return i % 2 === 0 ? letter : colors.inverse(letter);
4
+ };
5
5
  };
package/lib/styles.js CHANGED
@@ -48,6 +48,14 @@ var codes = {
48
48
  gray: [90, 39],
49
49
  grey: [90, 39],
50
50
 
51
+ brightRed: [91, 39],
52
+ brightGreen: [92, 39],
53
+ brightYellow: [93, 39],
54
+ brightBlue: [94, 39],
55
+ brightMagenta: [95, 39],
56
+ brightCyan: [96, 39],
57
+ brightWhite: [97, 39],
58
+
51
59
  bgBlack: [40, 49],
52
60
  bgRed: [41, 49],
53
61
  bgGreen: [42, 49],
@@ -56,6 +64,16 @@ var codes = {
56
64
  bgMagenta: [45, 49],
57
65
  bgCyan: [46, 49],
58
66
  bgWhite: [47, 49],
67
+ bgGray: [100, 49],
68
+ bgGrey: [100, 49],
69
+
70
+ bgBrightRed: [101, 49],
71
+ bgBrightGreen: [102, 49],
72
+ bgBrightYellow: [103, 49],
73
+ bgBrightBlue: [104, 49],
74
+ bgBrightMagenta: [105, 49],
75
+ bgBrightCyan: [106, 49],
76
+ bgBrightWhite: [107, 49],
59
77
 
60
78
  // legacy styles for colors pre v1.0.0
61
79
  blackBG: [40, 49],
package/package.json CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "name": "colors",
3
3
  "description": "get colors in your node.js console",
4
- "version": "1.3.0",
4
+ "version": "1.4.0",
5
5
  "author": "Marak Squires",
6
+ "contributors": [
7
+ {
8
+ "name": "DABH",
9
+ "url": "https://github.com/DABH"
10
+ }
11
+ ],
6
12
  "homepage": "https://github.com/Marak/colors.js",
7
13
  "bugs": "https://github.com/Marak/colors.js/issues",
8
14
  "keywords": [
@@ -33,7 +39,7 @@
33
39
  "safe.d.ts"
34
40
  ],
35
41
  "devDependencies": {
36
- "eslint": "^4.19.1",
37
- "eslint-config-google": "^0.9.1"
42
+ "eslint": "^5.2.0",
43
+ "eslint-config-google": "^0.11.0"
38
44
  }
39
45
  }