-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Proposal: add a console.write method #10119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
All the formatting const util = require('util');
process.stdout.write(util.format('my specially formatted string with %s', 'stuff')); If you want the convenience, why not write yourself a function for this? function writeFormat(...args) {
process.stdout.write(util.format(...args));
} Just my 2 cents, but I just don't see why this should be a core thing. |
Yeah IMHO this is something easily implemented in userland. Besides, I believe the |
I agree with @mscdex. Extending the console object with a method that doesn't exist in browser seems like something we shouldn't do. Users expect consitant behavior and apis from the console methods. |
Only in a pretty vague way, we don't follow the "spec" and various related behaviours are not actually the same (errors from closed streams etc). To be clear, this is required if we take #9744 as I stated here: #9470 (comment) |
In a perfect world, But its not a perfect world, and I'd prefer not to muddy it further, so while I understand the impetus, I don't think we should do this. -1 |
The current implementation of console.log is: Console.prototype.log = function log(...args) {
this._stdout.write(`${util.format.apply(null, args)}\n`);
}; Is it safe to assume that console.log will not do any magic in the future? If so, then the userland equivalent would be function console_log_sans_newline(...args) {
console._stdout.write(`${util.format.apply(null, args)}`);
}; If that is a bad assumption, where it may be possible for console.log to do something in addition to writing to the underlying _stdout buffer, IMHO there should be an equivalent. |
console.log will not do magic, it is purely a wrapper to do as you show above, format a string, write it to stdout |
I think @Fishrock123 has a point, but let's face it, the |
I'll close this out. It's clear from the discussion there is no broad support for this feature request. |
Often, I find myself needing to
console.log
a string without a new line and I useprocess.stdout.write
for that, but it would be cool if we can just use the global console object for that with all the extra features it supports (like printf, multiple args, etc..), and to make it so that when we have a custom console object, we'll get anoutput-without-a-new-line
method on that as well.Maybe
console.write()
? I think that matches the feature on other platforms.Happy to implement if you think this is a good idea.
The text was updated successfully, but these errors were encountered: