Created
August 3, 2010 13:54
-
-
Save jeromeetienne/506408 to your computer and use it in GitHub Desktop.
[PATCH] Support of %o console.log format + append non converted args
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 2fc85ee6b1b5dbc78328f94b539340dc2e15c1fc Mon Sep 17 00:00:00 2001 | |
From: Jerome Etienne <[email protected]> | |
Date: Tue, 3 Aug 2010 21:15:19 +0200 | |
Subject: [PATCH] Support of console.log %o + append unparsed params + noparam-ok | |
--- | |
src/node.js | 8 +++++--- | |
1 files changed, 5 insertions(+), 3 deletions(-) | |
diff --git a/src/node.js b/src/node.js | |
index 6d60113..9b777a2 100644 | |
--- a/src/node.js | |
+++ b/src/node.js | |
@@ -190,19 +190,21 @@ process.openStdin = function () { | |
// console object | |
-var formatRegExp = /%[sdj]/g; | |
+var formatRegExp = /%[sdjo]/g; | |
function format (f) { | |
var i = 1; | |
- var args = arguments; | |
+ var args = Array.prototype.slice.call(arguments); | |
return String(f).replace(formatRegExp, function (x) { | |
+ if( i == args.length ) return x; | |
switch (x) { | |
case '%s': return args[i++]; | |
case '%d': return +args[i++]; | |
case '%j': return JSON.stringify(args[i++]); | |
+ case '%o': return JSON.stringify(args[i++]); | |
default: | |
return x; | |
} | |
- }); | |
+ }) + (i == args.length ? '' : ' ') + args.slice(i).map(function(x){return typeof(x) == "string" ? x : JSON.stringify(x);}).join(' '); | |
} | |
global.console = {}; | |
-- | |
1.7.0.4 |
Author
jeromeetienne
commented
Aug 3, 2010
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment