From 5d9eb90263169521707ce75201ac6011e17d8f9a Mon Sep 17 00:00:00 2001 From: Josh Weinstein Date: Sun, 22 Sep 2019 16:10:31 -0700 Subject: [PATCH] Fixed: throws non-intuitive error on color.red(null) but not on colors.red(undefined) (#261) --- lib/colors.js | 4 ++-- package-lock.json | 2 +- package.json | 2 +- tests/safe-test.js | 7 +++++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/colors.js b/lib/colors.js index 0c1089f1..76c6d564 100644 --- a/lib/colors.js +++ b/lib/colors.js @@ -105,8 +105,8 @@ function applyStyle() { var args = Array.prototype.slice.call(arguments); var str = args.map(function(arg) { - // Use weak equality check so we can colorize null in safe mode - if (arg != undefined && arg.constructor === String) { + // Use weak equality check so we can colorize null/undefined in safe mode + if (arg != null && arg.constructor === String) { return arg; } else { return util.inspect(arg); diff --git a/package-lock.json b/package-lock.json index 045ee7f8..9986b6ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "colors", - "version": "1.3.3", + "version": "1.3.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index caf84035..30e1a717 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "colors", "description": "get colors in your node.js console", - "version": "1.3.3", + "version": "1.3.4", "author": "Marak Squires", "contributors": [ { diff --git a/tests/safe-test.js b/tests/safe-test.js index fd54acb7..95a21b7e 100644 --- a/tests/safe-test.js +++ b/tests/safe-test.js @@ -66,3 +66,10 @@ colors.setTheme({custom: ['red', 'italic', 'inverse']}); assert.equal(colors.custom(s), '\x1b[7m' + '\x1b[3m' + '\x1b[31m' + s + '\x1b[39m' + '\x1b[23m' + '\x1b[27m' ); + +// should not throw error on null or undefined values +var undef; +assert.equal(colors.yellow(undef), '\x1b[33mundefined\x1b[39m'); + +// was failing: +assert.equal(colors.red(null), '\x1b[31mnull\x1b[39m');