-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Limit depth of output in console.log for nested objects, and add console.dir #826
Conversation
js/console.ts
Outdated
const out: string[] = []; | ||
for (const a of args) { | ||
if (typeof a === "string") { | ||
out.push(a); | ||
} else { | ||
// tslint:disable-next-line:no-any | ||
out.push(stringify(new Set<any>(), a)); | ||
out.push(stringify(new Set<any>(), a, 0, options.depth || DEFAULT_MAX_DEPTH)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes we just want no depth at all. Perhaps you should add a check where if options.depth
is 0, take it instead of defaulting to 2. In case of null
, we could either default it to 0
(implying no depth), 2
(default depth), or Infinity
(implying lack of depth).
Same for line 136.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, now null
and undefined
(if user does not provide this option) defaults to 2
(default depth). Other values including 0
are treated as valid values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this null
treated as default to 2 is different with node:
in Node this null
is treated as unlimited depth
> var o = { a: { b: { c: { d: new Date } } } };
undefined
> console.log(o)
{ a: { b: { c: [Object] } } }
> console.dir(o, { depth: null });
{
a: { b: { c: { d: 2020-08-19T23:55:58.009Z } } }
}
@maxwyb Travis tests are failing. I think you might want to run |
Thanks for letting me know. Will work on it after a few hours when I get back home. |
@maxwyb - Could you please rebase / resolve conflicts - change looks reasonable - but I can't land it as is currently. |
…e_improvements Integrate changes into the refactored console.ts.
Thanks for taking a look! Seems like there's a small linting error left, I will resolve it after lunch and push. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks!
- Improve fetch headers (denoland#853) - Add deno.truncate (denoland#805) - Add copyFile/copyFileSync (denoland#863) - Limit depth of output in console.log for nested objects, and add console.dir (denoland#826) - Guess extensions on extension not provided (denoland#859) - Renames: deno.platform -> deno.platform.os deno.arch -> deno.platform.arch - Upgrade TS to 3.0.3 - Add readDirSync(), readDir() - Add support for TCP servers and clients. (denoland#884) Adds deno.listen(), deno.dial(), deno.Listener and deno.Conn.
- Improve fetch headers (#853) - Add deno.truncate (#805) - Add copyFile/copyFileSync (#863) - Limit depth of output in console.log for nested objects, and add console.dir (#826) - Guess extensions on extension not provided (#859) - Renames: deno.platform -> deno.platform.os deno.arch -> deno.platform.arch - Upgrade TS to 3.0.3 - Add readDirSync(), readDir() - Add support for TCP servers and clients. (#884) Adds deno.listen(), deno.dial(), deno.Listener and deno.Conn.
Bumped versions for 0.295.0 Co-authored-by: bartlomieju <bartlomieju@users.noreply.github.com>
Some improvements on Console to mimic the behavior of Node.js (if this's what we want to do):
console.log
only shows up to 3 levels for nested objects. Deeper structures are shown as[object]
.console.dir
function which supportsdepth
parameter, to customize output nested levels.This's my first PR to the deno repo and please let me know for any suggestions. Thanks guys!