Skip to content

Commit 5d9eb90

Browse files
jweinsteincbtDABH
authored andcommitted
Fixed: throws non-intuitive error on color.red(null) but not on colors.red(undefined) (#261)
1 parent aa012aa commit 5d9eb90

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

lib/colors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ function applyStyle() {
105105
var args = Array.prototype.slice.call(arguments);
106106

107107
var str = args.map(function(arg) {
108-
// Use weak equality check so we can colorize null in safe mode
109-
if (arg != undefined && arg.constructor === String) {
108+
// Use weak equality check so we can colorize null/undefined in safe mode
109+
if (arg != null && arg.constructor === String) {
110110
return arg;
111111
} else {
112112
return util.inspect(arg);

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "colors",
33
"description": "get colors in your node.js console",
4-
"version": "1.3.3",
4+
"version": "1.3.4",
55
"author": "Marak Squires",
66
"contributors": [
77
{

tests/safe-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,10 @@ colors.setTheme({custom: ['red', 'italic', 'inverse']});
6666
assert.equal(colors.custom(s),
6767
'\x1b[7m' + '\x1b[3m' + '\x1b[31m' + s +
6868
'\x1b[39m' + '\x1b[23m' + '\x1b[27m' );
69+
70+
// should not throw error on null or undefined values
71+
var undef;
72+
assert.equal(colors.yellow(undef), '\x1b[33mundefined\x1b[39m');
73+
74+
// was failing:
75+
assert.equal(colors.red(null), '\x1b[31mnull\x1b[39m');

0 commit comments

Comments
 (0)