GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — util: allow single-line format when break length is infinite · nodejs/node@cb4b89c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/util
    • inspect.js
  • test/parallel
    • test-util-inspect.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/util/inspect.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,6 +2622,14 @@ function isBelowBreakLength(ctx, output, start, base) {
26222622
// TODO(BridgeAR): Add unicode support. Use the readline getStringWidth
26232623
// function. Check the performance overhead and make it an opt-in in case it's
26242624
// significant.
2625+
// allow the single-line format if the length limit is infinite and no items have newlines
2626+
if (ctx.breakLength === Infinity) {
2627+
if (base !== '' && StringPrototypeIncludes(base, '\n')) return false;
2628+
for (let i = 0; i < output.length; i++) {
2629+
if (typeof output[i] === 'string' && StringPrototypeIncludes(output[i], '\n')) return false;
2630+
}
2631+
return true;
2632+
}
26252633
let totalLength = output.length + start;
26262634
if (totalLength + output.length > ctx.breakLength)
26272635
return false;
Collapse file

‎test/parallel/test-util-inspect.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4064,3 +4064,9 @@ ${error.stack.split('\n').slice(1).join('\n')}`,
40644064
assert.match(inspect(DOMException.prototype), /^\[object DOMException\] \{/);
40654065
delete Error[Symbol.hasInstance];
40664066
}
4067+
4068+
{
4069+
const obj = { a: 'short string', b: [1, 2], c: { d: true } };
4070+
const expected = "{ a: 'short string', b: [ 1, 2 ], c: { d: true } }";
4071+
assert.strictEqual(util.inspect(obj, { breakLength: Infinity }), expected);
4072+
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.