Skip to content

console.log and util.format formatting specifiers #10292

Description

@jsinmotion

The Chromium console supports format specifiers: https://developers.google.com/web/tools/chrome-devtools/console/console-write#string_substitution_and_formatting

In particular, both %i and %d specify an integral argument. Node.js does not perform the conversion for %i:

/* node.js */
> console.log("%i", 1234)
%i 1234
/* google chrome */
> console.log("%i", 1234)
1234

I think the fix is really simple: the relevant code is at https://github.com/nodejs/node/blob/master/lib/util.js#L86-L117 . Just adding the i case should be enough:

      switch (f.charCodeAt(i + 1)) {
        case 105: // 'i' <-- this is the new line, and it should appear just before the `d` case to make the fall through work
        case 100: // 'd'

If it makes sense I can send a PR

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

consoleIssues and PRs related to the console subsystem.feature requestIssues requesting new Node.js features.utilIssues and PRs related to the built-in util module.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions