| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | # object-inspect |
| 2 | |
| 3 | string representations of objects in node and the browser |
| 4 | |
| 5 | [](https://travis-ci.com/inspect-js/object-inspect) |
| 6 | |
| 7 | # example |
| 8 | |
| 9 | ## circular |
| 10 | |
| 11 | ``` js |
| 12 | var inspect = require('object-inspect'); |
| 13 | var obj = { a: 1, b: [3,4] }; |
| 14 | obj.c = obj; |
| 15 | console.log(inspect(obj)); |
| 16 | ``` |
| 17 | |
| 18 | ## dom element |
| 19 | |
| 20 | ``` js |
| 21 | var inspect = require('object-inspect'); |
| 22 | |
| 23 | var d = document.createElement('div'); |
| 24 | d.setAttribute('id', 'beep'); |
| 25 | d.innerHTML = '<b>wooo</b><i>iiiii</i>'; |
| 26 | |
| 27 | console.log(inspect([ d, { a: 3, b : 4, c: [5,6,[7,[8,[9]]]] } ])); |
| 28 | ``` |
| 29 | |
| 30 | output: |
| 31 | |
| 32 | ``` |
| 33 | [ <div id="beep">...</div>, { a: 3, b: 4, c: [ 5, 6, [ 7, [ 8, [ ... ] ] ] ] } ] |
| 34 | ``` |
| 35 | |
| 36 | # methods |
| 37 | |
| 38 | ``` js |
| 39 | var inspect = require('object-inspect') |
| 40 | ``` |
| 41 | |
| 42 | ## var s = inspect(obj, opts={}) |
| 43 | |
| 44 | Return a string `s` with the string representation of `obj` up to a depth of `opts.depth`. |
| 45 | |
| 46 | Additional options: |
| 47 | - `quoteStyle`: must be "single" or "double", if present. Default `'single'` for strings, `'double'` for HTML elements. |
| 48 | - `maxStringLength`: must be `0`, a positive integer, `Infinity`, or `null`, if present. Default `Infinity`. |
| 49 | - `customInspect`: When `true`, a custom inspect method function will be invoked. Default `true`. |
| 50 | - `indent`: must be "\t", `null`, or a positive integer. Default `null`. |
| 51 | |
| 52 | # install |
| 53 | |
| 54 | With [npm](https://npmjs.org) do: |
| 55 | |
| 56 | ``` |
| 57 | npm install object-inspect |
| 58 | ``` |
| 59 | |
| 60 | # license |
| 61 | |
| 62 | MIT |