Skip to content

Commit

Permalink
Print with multiple lines when inspecting large objects
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Nov 6, 2023
1 parent bde1ab0 commit 59beb73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-poets-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nxjs-runtime': patch
---

Print with multiple lines when inspecting large objects
18 changes: 14 additions & 4 deletions packages/runtime/src/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,20 @@ function printObject(v: any, opts: InspectOptions) {
ctor && ctor !== Object && typeof ctor.name === 'string'
? `${ctor.name} `
: '';
const contents =
keys.length === 0
? ''
: ` ${keys.map((k) => `${k}: ${inspect(v[k], opts)}`).join(', ')} `;
let contents = '';
if (keys.length > 0) {
let len = 0;
const parts = keys.map((k) => {
const l = `${k}: ${inspect(v[k], opts)}`;
len += l.length;
return `${k}: ${inspect(v[k], opts)}`;
});
if (len > 60) {
contents = parts.map((p) => `\n ${p}`).join('') + '\n';
} else {
contents = ` ${parts.join(', ')} `;
}
}
return `${className}{${contents}}`;
}

Expand Down

0 comments on commit 59beb73

Please sign in to comment.