Skip to content
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

util.format seems to insert newline charaters #26118

Closed
bodyslam opened this issue Feb 15, 2019 · 2 comments
Closed

util.format seems to insert newline charaters #26118

bodyslam opened this issue Feb 15, 2019 · 2 comments
Labels
question Issues that look for answers. util Issues and PRs related to the built-in util module.

Comments

@bodyslam
Copy link

bodyslam commented Feb 15, 2019

For arrays of length 30 or greater newline characters are inserted

example

const test31 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1];
const test20 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0];

> util.format(test20)
'[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 ]'
> util.format(test31)
'[ 1,\n  2,\n  3,\n  4,\n  5,\n  6,\n  7,\n  8,\n  9,\n  0,\n  1,\n  2,\n  3,\n  4,\n  5,\n  6,\n  7,\n  8,\n  9,\n  0,\n  1,\n  2,\n  3,\n  4,\n  5,\n  6,\n  7,\n  8,\n  9,\n  0,\n  1 ]'

Originally discovered while debugging buynan (ticket here: trentm/node-bunyan#617)

Is there any way to suppress the newline characters?

@addaleax
Copy link
Member

Is there any way to suppress the newline characters?

Yes; see the documentation:

breakLength <integer> The length at which an object's keys are split across multiple lines. Set to Infinity to format an object as a single line.

So util.inspect(test31, { breakLength: Infinity }) does the trick.

@addaleax addaleax added question Issues that look for answers. util Issues and PRs related to the built-in util module. labels Feb 15, 2019
@bodyslam
Copy link
Author

bodyslam commented Feb 15, 2019

Thank you so much @addaleax! That did the trick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

No branches or pull requests

2 participants