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
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2622,6 +2622,14 @@ function isBelowBreakLength(ctx, output, start, base) { |
2622 | 2622 | // TODO(BridgeAR): Add unicode support. Use the readline getStringWidth |
2623 | 2623 | // function. Check the performance overhead and make it an opt-in in case it's |
2624 | 2624 | // 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 | + } |
2625 | 2633 | let totalLength = output.length + start; |
2626 | 2634 | if (totalLength + output.length > ctx.breakLength) |
2627 | 2635 | return false; |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4064,3 +4064,9 @@ ${error.stack.split('\n').slice(1).join('\n')}`, |
4064 | 4064 | assert.match(inspect(DOMException.prototype), /^\[object DOMException\] \{/); |
4065 | 4065 | delete Error[Symbol.hasInstance]; |
4066 | 4066 | } |
| 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 | +} |