Permalink
Browse files

Fixed format, so it wouldn’t blow up if %d argument is null or undefi…

…ned + ensure that numbers will be numbers
  • Loading branch information...
1 parent 2c1ca40 commit a585c5bbb3fd02602f947890a78aee9a78439308 @DmitryBaranovskiy DmitryBaranovskiy committed with ry Jul 22, 2010
Showing with 3 additions and 4 deletions.
  1. +3 −4 src/node.js
View
7 src/node.js
@@ -190,15 +190,14 @@ process.openStdin = function () {
// console object
-
+var formatRegExp = /%[sdj]/g;
function format (f) {
var i = 1;
var args = arguments;
- if (!(f instanceof String)) f = String(f);
- return f.replace(/%([sdj])/g, function (x) {
+ return String(f).replace(formatRegExp, function (x) {
switch (x) {
case '%s': return args[i++];
- case '%d': return args[i++].toString();
+ case '%d': return +args[i++];
case '%j': return JSON.stringify(args[i++]);
default:
return x;

0 comments on commit a585c5b

Please sign in to comment.