You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
util: discrepancy in format() docs vs behavior #935
There is a discrepancy between how the docs say util.format() works, and what really happens. The docs state:
If there are more arguments than placeholders, the extra arguments are converted to strings with util.inspect() and these strings are concatenated, delimited by a space.
However, only objects and symbols actually use util.inspect(). The required change is trivial, and I think we should bring behavior into line with what the docs say, but this is a slightly breaking change (there is at least one test that fails).
Is the issue that primitives are ToString'd? I think the output of util.inspect() is the same except in the case of strings, util.format() wraps them in quotes.
That would make for a mildly annoying change: console.log(util.format('and then:', 'nothing')) would start printing and then: 'nothing' instead of and then: nothing. I would move to just update the documentation.
Activity
bnoordhuis commentedon Feb 24, 2015
Is the issue that primitives are ToString'd? I think the output of util.inspect() is the same except in the case of strings, util.format() wraps them in quotes.
That would make for a mildly annoying change:
console.log(util.format('and then:', 'nothing'))would start printingand then: 'nothing'instead ofand then: nothing. I would move to just update the documentation.cjihrig commentedon Feb 24, 2015
Yep, that's the problem. A doc change sounds appropriate.
brendanashworth commentedon Mar 25, 2015
Closed as fixed in
4581421.