{"id":13527051,"url":"https://github.com/grantcarthew/node-console-probe","last_synced_at":"2025-07-08T13:09:01.776Z","repository":{"id":57206066,"uuid":"118556238","full_name":"grantcarthew/node-console-probe","owner":"grantcarthew","description":"Inspect JavaScript object methods and properties in the console.","archived":false,"fork":false,"pushed_at":"2019-10-14T23:46:54.000Z","size":702,"stargazers_count":133,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-29T11:43:34.676Z","etag":null,"topics":["console","discover","inspect","member","method","node","object","probe","property"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grantcarthew.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-23T04:09:09.000Z","updated_at":"2023-11-08T22:54:26.000Z","dependencies_parsed_at":"2022-09-18T00:50:42.663Z","dependency_job_id":null,"html_url":"https://github.com/grantcarthew/node-console-probe","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grantcarthew%2Fnode-console-probe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grantcarthew%2Fnode-console-probe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grantcarthew%2Fnode-console-probe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grantcarthew%2Fnode-console-probe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grantcarthew","download_url":"https://codeload.github.com/grantcarthew/node-console-probe/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252798832,"owners_count":21805882,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["console","discover","inspect","member","method","node","object","probe","property"],"created_at":"2024-08-01T06:01:39.959Z","updated_at":"2025-05-07T02:02:04.255Z","avatar_url":"https://github.com/grantcarthew.png","language":"JavaScript","readme":"# console-probe\n\nInspect JavaScript object methods and properties in the console.\n\n[![Maintainability][cc-maintain-badge]][cc-maintain-url]\n[![Build Status][travisci-image]][travisci-url]\n[![js-standard-style][js-standard-image]][js-standard-url]\n[![Patreon Donation][patreon-image]][patreon-url]\n\n![Event Emitter Example][example-eventemitter-image]\n\n[![NPM][nodei-npm-image]][nodei-npm-url]\n\nProvides colourful functions to inspect JavaScript objects.\n\n* The `probe()` function outputs a prototype hierarchy tree to the console.\n* The `json()` function safely writes a stringified object output to the console.\n* The `yaml()` function converts objects into yaml format and outputs to the console.\n* The `ls()` function converts objects into a colourful format and outputs to the console.\n\n## Installing\n\n* Node: v6.0.0 or later.\n* Browser: Not tested\n\n```sh\nnpm install --save-dev console-probe\n```\n\n## Quick Start\n\n__Not recommended for production environments__\n\n\n```js\n\nconst cp = require('./console-probe')\nconst arrLen = 2\n\nconst aussieSlang = {\n  'name': 'Aussie Slang Words',\n  'gday': Infinity,\n  'maccas': Number.NaN,\n  'arvo': undefined,\n  'straya': null,\n  'footy': {specky: true},\n  'biccy': (size, toppings) =\u003e {},\n  'servo': true,\n  'choccy': Symbol('Mmmmm...'),\n  'bottle-o': Error('Cheers mate! My shout next'),\n  'tinny': 42,\n  'coppa': new Date(),\n  'tradie': 'She\\'ll be right mate?',\n  'postie': /a.long.regexp.that.keeps.giving/,\n  'garbo': [1, 2, 3],\n  'muso': new Int8Array(arrLen),\n  'cabbie': new Uint8Array(arrLen),\n  'ambo': new Uint8ClampedArray(arrLen),\n  'prezzie': new Int16Array(arrLen),\n  'chrissie': new Uint16Array(arrLen),\n  'cuppa': new Int32Array(arrLen),\n  'mate': new Uint32Array(arrLen),\n  'snag': new Float32Array(arrLen),\n  'drongo': new Float64Array(arrLen),\n  'fairDinkum': new Map([['foo', 'bar']]),\n  'bonza': new Set([['foo', 'bar']]),\n  'tooRight': new WeakMap(),\n  'dunny': new WeakSet(),\n  'cobber': new ArrayBuffer(arrLen),\n  'barbie': new SharedArrayBuffer(arrLen),\n  'stickybeak': Atomics,\n  'stoked': new DataView(new ArrayBuffer(arrLen)),\n  'ripper': Promise.resolve(),\n  'mongrel': (function * () {})(),\n  'holyDooley': function * (foo, bar) {},\n  'roo': async function (foo, bar) {}\n}\nconst secret = Symbol('Hidden Property')\naussieSlang[secret] = 'Bogan'\n\n// Calling console-probe functions.\ncp.probe(aussieSlang) // Writes a prototype tree to the console\ncp.json(aussieSlang) // Writes a JSON formatted object to the console\ncp.yaml(aussieSlang) // Writes a YAML formatted object to the console\ncp.ls(aussieSlang) // Writes a formatted object to the console\n\n// Adding console-probe functions to the console.\nconsole.probe(aussieSlang) // Throws exception 'console.probe is not a function'\nconsole.json(aussieSlang) // Throws exception 'console.json is not a function'\nconsole.yaml(aussieSlang) // Throws exception 'console.yaml is not a function'\nconsole.ls(aussieSlang) // Throws exception 'console.ls is not a function'\ncp.apply()\nconsole.probe(aussieSlang) // Writes a prototype tree to the console\nconsole.json(aussieSlang) // Writes a JSON formatted object to the console\nconsole.yaml(aussieSlang) // Writes a YAML formatted object to the console\nconsole.ls(aussieSlang) // Writes a formatted object to the console\n\n// Adding console-probe functions to an object.\nconst foo = {}\ncp.apply(foo)\nfoo.probe(aussieSlang) // Writes prototype tree to the console\nfoo.json(aussieSlang) // Writes a JSON formatted object to the console\nfoo.yaml(aussieSlang) // Writes a YAML formatted object to the console\nfoo.ls(aussieSlang) // Writes a formatted object to the console\n\n```\n\nThe above code will produce the following results when it writes to the console.\n\n### The `probe` function output:\n\n_Note: Type detection errors will display as `[Unknown]`._\n\n![Example Probe Output][example-probe-image]\n\n### The `json` function output:\n\n![Example Json Output][example-json-image]\n\n### The `yaml` function output:\n\n![Example Yaml Output][example-yaml-image]\n\n### The `ls` function output:\n\n![Example ls Output][example-ls-image]\n\n## Rational\n\nThere are many amazing packages on `npm`. Many of those packages are not well documented. Rather than go straight to reading source code I wrote `console-probe` to inspect objects and discover methods and properties. Using Node.js with inspect is often a better approach however I don't always have it running; this is when `console-probe` comes in handy.\n\n## Function\n\nThe `console-probe` package provides four functions that will write to the console:\n\n* `probe(obj)`: The probe function uses `Object.getOwnPropertyNames()` and `Object.getOwnPropertySymbols()` to enumerate the members of an object through its prototype hierarchy. Using the type list from [MDN][jstypes-url] the types are detected. After a little formatting the result is written to the console using the [archy][archy-url] package with some colour added by [chalk][chalk-url].\n* `json(obj, replacer, spacer, color)`: Uses [fast-safe-stringify][fss-url] and [json-colorizer][json-colorizer-url] to safely write the stringified object out to the console.\n* `yaml(obj, options, indentation)`: A simple wrapper around the [prettyjson][prettyjson-url] package render function.\n* `ls(obj)`: A simple wrapper around the [jsome][jsome-url] package render function.\n\n## API\n\n### `probe` Function\n\n__Description:__ Inspects the passed objects properties and methods, then the prototype of the passed object, and so on till the last prototype is analyzed. A tree of the properties and methods on each prototype is written to the console.\n\n__Method Signature:__ `probe(object)`\n\n__Parameter:__ `object` can be any JavaScript type.\n\n__Details:__\n\n* Passing either `null` or `undefined` will write `[console-probe] Invalid Type:` to the console.\n* String values with newline characters are stripped from string stubs.\n\n__Example:__\n\n```js\nconst cp = require('console-probe')\ncp.probe({ key: 'value' })\n// Writes the object prototype hierarchy to the console\n// See above for an example of the output\n```\n\n### `json` Function\n\n__Description:__ This function simply calls [fast-safe-stringify][fss-url] and then adds color via [json-colorizer][json-colorizer-url]. Once that is done it writes the result to the console.\n\n__Method Signature:__ `json(object, replacer, spacer, color)`\n\n__Parameter:__\n\n* `object` can be any object you wish to stringify.\n* `replacer` alters the behavior of the stringification process.\n* `spacer` inserts white space into the output JSON string for readability purposes.\n* `color` enables customization of the colour displayed.\n\n__Details:__\n\n* The `json` function defaults to `replacer = null` and `spacer = 2`.\n* See both [fast-safe-stringify][fss-url] and [JSON.stringify][json-stringify-url] for more details.\n* Change the color displayed using a color object from the [json-colorizer][json-colorizer-url] options.\n\n__Example:__\n\n```js\nconst cp = require('console-probe')\ncp.json({ key: 'value' })\n// Outputs the following to the console:\n// {\n//   \"key\": \"value\"\n// }\n```\n\n### `yaml` Function\n\n__Description:__ This function wraps the [prettyjson][prettyjson-url] render function and writes the result to the console. The result is a colorized formatted [YAML][yaml-url] representation of the object data.\n\n__Signature:__ `yaml(object, options, indentation)`\n\n__Parameter:__\n\n* `object` can be any object you wish to display in [YAML][yaml-url] format.\n* `options` should hold options for the [prettyjson][prettyjson-url] render function.\n* `indentation` controls the indentation for the YAML output.\n\n__Details:__\n\n* The `yaml` function is simply a wrapper around the [prettyjson][prettyjson-url] package.\n* See the [prettyjson][prettyjson-url] documentation and code for the options and indentation.\n\n__Example:__\n\n```js\nconst cp = require('console-probe')\ncp.yaml({ key: 'value' })\n// Outputs the following to the console:\n// key: value\n```\n\n### `ls` Function\n\n__Description:__ This function wraps the [jsome][jsome-url] render function and writes the result to the console. The result is a colorized formatted representation of the object data.\n\n__Signature:__ `ls(object)`\n\n__Parameter:__\n\n* `object` can be any object you wish to display.\n\n__Details:__\n\n* The `ls` function is simply a wrapper around the [jsome][jsome-url] package.\n* See the [jsome][jsome-url] documentation for more detail.\n\n__Example:__\n\n```js\nconst cp = require('console-probe')\ncp.ls({ key: 'value' })\n// Outputs the following to the console:\n// {\n//   key: \"value\"\n// }\n```\n### `apply` Function\n\n__Signature:__ `apply(object)`\n\n__Parameter:__ `object` can be any object you would like to add `console-probe` functions to.\n\n__Details:__\n\n* The `apply` function is a convenience method to add the `console-probe` functions to an object.\n* If no `object` is passed to the `apply` function then the `console-probe` functions will be added to the `console` object.\n* Passing an object, such as a logger, will add the `console-probe` functions to the object.\n\n__Example:__\n\n```js\nconst cp = require('console-probe')\ncp.apply()\n// console now has a probe, json, yaml, and ls functions.\n\nconst foo = {}\ncp.apply(foo)\n// foo now has a probe, json, yaml, and ls functions.\n```\n\nAnother approach to simply augment the console:\n\n```js\nrequire('console-probe').apply()\n// console.probe, console.json, console.yaml, and console.ls are now ready for use.\n```\n\n## About the Owner\n\nI, Grant Carthew, am a technologist, trainer, and Dad from Queensland, Australia. I work on code in a number of personal projects and when the need arises I build my own packages.\n\nThis project exists because I wanted to inspect objects from the console.\n\nEverything I do in open source is done in my own time and as a contribution to the open source community.\n\nIf you are using my projects and would like to thank me or support me, please click the Patreon link below.\n\n[![Patreon Donation][patreon-image]][patreon-url]\n\nSee my [other projects on NPM](https://www.npmjs.com/~grantcarthew).\n\n## Contributing\n\n1.  Fork it!\n2.  Create your feature branch: `git checkout -b my-new-feature`\n3.  Commit your changes: `git commit -am 'Add some feature'`\n4.  Push to the branch: `git push origin my-new-feature`\n5.  Submit a pull request :D\n\n## Change Log\n\n- v3.3.2 [2019-10-14]: Added 'name' to the name getter.\n- v3.3.1 [2019-10-14]: Fixed Getter support (#5). Removed NSP from readme.\n- v3.3.0 [2018-07-05]: Added new method `ls`. Fixed README badges. Fixed null/undefined error.\n- v3.2.1 [2018-07-05]: Added `BigInt` type support. Updated dependencies.\n- v3.2.0 [2018-03-02]: Multiple type support. Probe format updated.\n- v3.1.0 [2018-02-19]: Added colour to json. Added yaml function.\n- v3.0.0 [2018-02-18]: Added json function. Improved API. Removed newline chrs.\n- v2.0.4 [2018-01-29]: Changed node label format.\n- v2.0.3 [2018-01-26]: Fix example image url.\n- v2.0.2 [2018-01-26]: Added support for arrays and values. Fixed sort.\n- v2.0.1 [2018-01-25]: Added repository url to package.json.\n- v2.0.0 [2018-01-24]: Changed API. Improved type support.\n- v1.0.2 [2018-01-23]: Updated Readme.\n- v1.0.1 [2018-01-23]: Updated NSP link.\n- v1.0.0 [2018-01-23]: Initial release. \n\n[cc-maintain-badge]: https://api.codeclimate.com/v1/badges/805e88a221e165ecda12/maintainability\n[cc-maintain-url]: https://codeclimate.com/github/grantcarthew/node-console-probe/maintainability\n[travisci-image]: https://travis-ci.org/grantcarthew/node-console-probe.svg?branch=master\n[travisci-url]: https://travis-ci.org/grantcarthew/node-console-probe\n[js-standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg\n[js-standard-url]: http://standardjs.com/\n[mppg-url]: https://github.com/grantcarthew/node-console-probe\n[bithound-code-image]: https://www.bithound.io/github/grantcarthew/node-console-probe/badges/code.svg\n[bithound-code-url]: https://www.bithound.io/github/grantcarthew/node-console-probe\n[patreon-image]: https://img.shields.io/badge/patreon-donate-yellow.svg\n[patreon-url]: https://www.patreon.com/grantcarthew\n[nodei-npm-image]: https://nodei.co/npm/console-probe.png?downloads=true\u0026downloadRank=true\u0026stars=true\n[nodei-npm-url]: https://nodei.co/npm/console-probe/\n[archy-url]: https://www.npmjs.com/package/archy\n[chalk-url]: https://www.npmjs.com/package/chalk\n[fss-url]: https://www.npmjs.com/package/fast-safe-stringify\n[example-eventemitter-image]: https://cdn.rawgit.com/grantcarthew/node-console-probe/b7f56e39/images/eventemitter.png\n[example-probe-image]: https://cdn.rawgit.com/grantcarthew/node-console-probe/b7f56e39/images/aussieslang-probe.png\n[example-json-image]: https://cdn.rawgit.com/grantcarthew/node-console-probe/b7f56e39/images/aussieslang-json.png\n[example-yaml-image]: https://cdn.rawgit.com/grantcarthew/node-console-probe/b7f56e39/images/aussieslang-yaml.png\n[example-ls-image]: https://cdn.rawgit.com/grantcarthew/node-console-probe/4ea69e0c/images/aussieslang-ls.png\n[json-stringify-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify\n[prettyjson-url]: https://www.npmjs.com/package/prettyjson\n[json-colorizer-url]: https://www.npmjs.com/package/json-colorizer\n[yaml-url]: http://yaml.org/\n[jsome-url]: https://www.npmjs.com/package/jsome\n[jstypes-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects\n","funding_links":["https://www.patreon.com/grantcarthew"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrantcarthew%2Fnode-console-probe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrantcarthew%2Fnode-console-probe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrantcarthew%2Fnode-console-probe/lists"}