colors 1.2.4 → 1.3.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.
@@ -37,7 +37,7 @@ console.log('Setting themes is useful');
37
37
  // Load theme with JSON literal
38
38
  colors.setTheme({
39
39
  silly: 'rainbow',
40
- input: 'grey',
40
+ input: 'blue',
41
41
  verbose: 'cyan',
42
42
  prompt: 'grey',
43
43
  info: 'green',
@@ -54,14 +54,14 @@ console.log(colors.error('this is an error'));
54
54
  // outputs yellow text
55
55
  console.log(colors.warn('this is a warning'));
56
56
 
57
- // outputs grey text
57
+ // outputs blue text
58
58
  console.log(colors.input('this is an input'));
59
59
 
60
60
 
61
61
  // console.log('Generic logging theme as file'.green.bold.underline);
62
62
 
63
63
  // Load a theme from file
64
- colors.setTheme(__dirname + '/../themes/generic-logging.js');
64
+ colors.setTheme(require(__dirname + '/../themes/generic-logging.js'));
65
65
 
66
66
  // outputs red text
67
67
  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;
Binary file
package/lib/colors.js CHANGED
@@ -105,7 +105,11 @@ function applyStyle() {
105
105
  var args = Array.prototype.slice.call(arguments);
106
106
 
107
107
  var str = args.map(function(arg) {
108
- return arg.constructor === String ? arg : util.inspect(arg);
108
+ if (arg != undefined && arg.constructor === String) {
109
+ return arg;
110
+ } else {
111
+ return util.inspect(arg);
112
+ }
109
113
  }).join(' ');
110
114
 
111
115
  if (!colors.enabled || !str) {
@@ -121,7 +125,9 @@ function applyStyle() {
121
125
  var code = ansiStyles[nestedStyles[i]];
122
126
  str = code.open + str.replace(code.closeRe, code.open) + code.close;
123
127
  if (newLinesPresent) {
124
- str = str.replace(newLineRegex, code.close + '\n' + code.open);
128
+ str = str.replace(newLineRegex, function(match) {
129
+ return code.close + match + code.open;
130
+ });
125
131
  }
126
132
  }
127
133
 
@@ -179,10 +185,10 @@ colors.zalgo = require('./custom/zalgo');
179
185
 
180
186
  // maps
181
187
  colors.maps = {};
182
- colors.maps.america = require('./maps/america');
183
- colors.maps.zebra = require('./maps/zebra');
184
- colors.maps.rainbow = require('./maps/rainbow');
185
- colors.maps.random = require('./maps/random');
188
+ colors.maps.america = require('./maps/america')(colors);
189
+ colors.maps.zebra = require('./maps/zebra')(colors);
190
+ colors.maps.rainbow = require('./maps/rainbow')(colors);
191
+ colors.maps.random = require('./maps/random')(colors);
186
192
 
187
193
  for (var map in colors.maps) {
188
194
  (function(map) {
@@ -73,32 +73,30 @@ module['exports'] = function() {
73
73
  } else {
74
74
  if (typeof(theme[prop]) === 'string') {
75
75
  colors[prop] = colors[theme[prop]];
76
- addProperty(prop, function() {
77
- return colors[theme[prop]](this);
78
- });
79
76
  } 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
- });
77
+ var tmp = colors[theme[prop][0]];
78
+ for (var t = 1; t < theme[prop].length; t++) {
79
+ tmp = tmp[theme[prop][t]];
80
+ }
81
+ colors[prop] = tmp;
87
82
  }
83
+ addProperty(prop, function() {
84
+ return colors[prop](this);
85
+ });
88
86
  }
89
87
  });
90
88
  }
91
89
 
92
90
  colors.setTheme = function(theme) {
93
91
  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
- }
92
+ console.log('colors.setTheme now only accepts an object, not a string. ' +
93
+ 'If you are trying to set a theme from a file, it is now your (the ' +
94
+ 'caller\'s) responsibility to require the file. The old syntax ' +
95
+ 'looked like colors.setTheme(__dirname + ' +
96
+ '\'/../themes/generic-logging.js\'); The new syntax looks like '+
97
+ 'colors.setTheme(require(__dirname + ' +
98
+ '\'/../themes/generic-logging.js\'));');
99
+ return;
102
100
  } else {
103
101
  applyTheme(theme);
104
102
  }
@@ -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,6 +1,4 @@
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
3
  'blue', 'white', 'cyan', 'magenta'];
6
4
  return function(letter, i, exploded) {
@@ -9,4 +7,4 @@ module['exports'] = (function() {
9
7
  available[Math.round(Math.random() * (available.length - 2))]
10
8
  ](letter);
11
9
  };
12
- })();
10
+ };
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/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.2.4",
4
+ "version": "1.3.2",
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-config-google": "^0.9.1",
43
+ "eslint": "^5.4.0"
38
44
  }
39
45
  }