diff options
Diffstat (limited to 'node_modules/colors/lib/colors.js')
-rw-r--r-- | node_modules/colors/lib/colors.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/node_modules/colors/lib/colors.js b/node_modules/colors/lib/colors.js index 7ca90fa90..9c7f1d141 100644 --- a/node_modules/colors/lib/colors.js +++ b/node_modules/colors/lib/colors.js @@ -62,7 +62,16 @@ var stylize = colors.stylize = function stylize(str, style) { return str+''; } - return ansiStyles[style].open + str + ansiStyles[style].close; + var styleMap = ansiStyles[style]; + + // Stylize should work for non-ANSI styles, too + if(!styleMap && style in colors){ + // Style maps like trap operate as functions on strings; + // they don't have properties like open or close. + return colors[style](str); + } + + return styleMap.open + str + styleMap.close; }; var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g; @@ -105,7 +114,8 @@ function applyStyle() { var args = Array.prototype.slice.call(arguments); var str = args.map(function(arg) { - 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); |