Skip to content

Commit

Permalink
[Fix] when truncating a deep array, note it as [Array] instead of j…
Browse files Browse the repository at this point in the history
…ust `[Object]`

This also matches `util.inspect`.
  • Loading branch information
ljharb committed Feb 12, 2020
1 parent 81ebdd4 commit f74c82d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = function inspect_(obj, options, depth, seen) {
var maxDepth = typeof opts.depth === 'undefined' ? 5 : opts.depth;
if (typeof depth === 'undefined') { depth = 0; }
if (depth >= maxDepth && maxDepth > 0 && typeof obj === 'object') {
return '[Object]';
return isArray(obj) ? '[Array]' : '[Object]';
}

if (typeof seen === 'undefined') {
Expand Down
4 changes: 2 additions & 2 deletions test/deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ var test = require('tape');
test('deep', function (t) {
t.plan(2);
var obj = [[[[[[500]]]]]];
t.equal(inspect(obj), '[ [ [ [ [ [Object] ] ] ] ] ]');
t.equal(inspect(obj, { depth: 2 }), '[ [ [Object] ] ]');
t.equal(inspect(obj), '[ [ [ [ [ [Array] ] ] ] ] ]');
t.equal(inspect(obj, { depth: 2 }), '[ [ [Array] ] ]');
});

0 comments on commit f74c82d

Please sign in to comment.