diff --git a/index.js b/index.js index e31269a..d32a62f 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,9 @@ module.exports = function inspect_ (obj, opts, depth, seen) { if (!opts) opts = {}; - var maxDepth = opts.depth || 5; + var maxDepth = opts.depth === undefined ? 5 : opts.depth; if (depth === undefined) depth = 0; - if (depth > maxDepth) return '...'; + if (depth > maxDepth && maxDepth > 0) return '...'; if (seen === undefined) seen = []; else if (seen.indexOf(obj) >= 0) { diff --git a/readme.markdown b/readme.markdown index 28b4fa7..86e4e3c 100644 --- a/readme.markdown +++ b/readme.markdown @@ -4,7 +4,16 @@ inspect objects in node and in the browser # example -## browser +## circular + +``` js +var inspect = require('object-inspect'); +var obj = { a: 1, b: [3,4] }; +obj.c = obj; +console.log(inspect(obj)); +``` + +## dom element ``` js var inspect = require('object-inspect'); @@ -22,4 +31,25 @@ output: [
...
, { a: 3, b: 4, c: [ 5, 6, [ 7, [ 8, [ ... ] ] ] ] } ] ``` -## node +# methods + +``` js +var inspect = require('object-inspect') +``` + +## var s = inspect(obj, opts={}) + +Return a string `s` with the string representation of `obj` up to a depth of +`opts.depth`. + +# install + +With [npm](https://npmjs.org) do: + +``` +npm install object-inspect +``` + +# license + +MIT