Skip to content

Commit

Permalink
[Robustness] use typeof instead of comparing to literal undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 28, 2017
1 parent 81edd34 commit 5ca6f60
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ var objectToString = Object.prototype.toString;

module.exports = function inspect_ (obj, opts, depth, seen) {
if (!opts) opts = {};
var maxDepth = opts.depth === undefined ? 5 : opts.depth;
if (depth === undefined) depth = 0;

var maxDepth = typeof opts.depth === 'undefined' ? 5 : opts.depth;
if (typeof depth === 'undefined') depth = 0;
if (depth >= maxDepth && maxDepth > 0 && obj && typeof obj === 'object') {
return '[Object]';
}
if (seen === undefined) seen = [];

if (typeof seen === 'undefined') seen = [];
else if (indexOf(seen, obj) >= 0) {
return '[Circular]';
}
Expand Down

0 comments on commit 5ca6f60

Please sign in to comment.