Description
What is the problem this feature will solve?
console.log()
, util.inspect()
and REPL prints can become unreadable if you happen to have a very large Set
or Map
as part of the data you’re passing. But if you have a very large Array
, the print helpfully cuts off after 100 items (adding something like ... 900 more items
at the end).
What is the feature you are proposing to solve the problem?
- In 2015, support for
Set
andMap
were added toutil.inspect
: util: support inspecting Map, Set, and Promise #1471 - In 2016, the
maxArrayLength
option (defaulting to 100) was added toutil.inspect
: util: truncate inspect array and typed array #6334 - In 2018,
maxArrayLength
was extended to also coverWeakSet
andWeakMap
: util: improve Weak(Map|Set) support #19259
So maxArrayLength
covers Array, TypedArray, WeakMap and WeakSet, but not plain Map and Set.
In the last PR I linked to above, there was even a TODO comment at one point suggesting to rename maxArrayLength
to maxEntries
: #19259 (comment)
I suggest that maxArrayLength
keeps it name (renaming would be another issue), but also applies to Map and Set.
What alternatives have you considered?
I could add something like this to my application:
Set.prototype[util.inspect.custom] = function(depth, opts, inspect) {
return `Set(${this.size}) ${inspect(Array.from(this))}`;
};
But it feels a bit dirty, and I also seem to lose color that way. I also need to do it in every project, and it’s unclear how to get it into the REPL.