From b38496e03bcc7937bcf79f2d7f97cd17bfeaec23 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Sat, 31 May 2014 14:24:59 -0700 Subject: [PATCH] node: map "%o" to `util.inspect()` --- node.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/node.js b/node.js index 87a94c2..6111755 100644 --- a/node.js +++ b/node.js @@ -4,6 +4,7 @@ */ var tty = require('tty'); +var util = require('util'); /** * This is the Node.js implementation of `debug()`. @@ -34,6 +35,16 @@ var prevColor = 0; var useColors = tty.isatty(1) || process.env.DEBUG_COLORS; +/** + * Map %o to `util.inspect()`, since Node doesn't do that out of the box. + */ + +exports.formatters.o = function(v) { + var str = (useColors ? '\u001b[0m' : '') + + util.inspect(v, { colors: useColors }).replace(/\s*\n\s*/g, ' '); + return str; +}; + /** * Select a color. *