Socket
Book a DemoInstallSign in
Socket

deep-inspect

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-inspect

Inspect inherited properties. Inspired by Node.js's util

0.0.2
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

deep-inspect

A function to inspect inherited properties as well

NPM

Build
Status Coverage
Status npm version David DM

Installation

npm install deep-inspect

Options

The second argument to this function will be an options object. It accepts the following values. Please note that all are optional fields.

  • showHidden
  • depth
  • parentChainLevel

See below for explanations of the options.

showHidden

Setting this option to true will show all the enumerable properties of the object. Normally, when you iterate an object with a for..in loop or with Object.keys, the non-enumerable properties will not be shown.

This must be a boolean value and the default value is false.

depth

If the object is nested structure or the object has many child properties then setting this option to a valid positive 32 bit integer value, will list all the properties of the nested structure as well, till the level specified by depth is reached.

This must be a valid 32 bit integer value and the default value is 1.

parentChainLevel

This option allows to explore the inheritance chain as well. It will go to the depth mentioned in parentChainLevel and list down all the properties of all the objects on the way.

There is no default value, but if not provided this will be ignored and none of the parent objects in the prototype chain will be inspected.

Usage

Inspecting primitives

var inspect = require('deep-inspect');
inspect(1);
// 1
inspect('thefourtheye');
// "thefourtheye"
inspect();
// undefined

Inspecting simple objects

var inspect = require('deep-inspect');
inspect([]);
// []
inspect({});
// {}
inspect({1: '2'});
// Object
// └─┬ Key: "1"',
//   └── "2"'

Inspecting hidden (non-enumerable) properties

var inspect = require('deep-inspect');
var a = {};
Object.defineProperties(a, {
    one: {enumerable: true,  value: 'one'},
    two: {enumerable: false, value: 'two'},
});
inspect(a, {showHidden: true});
// Object
// ├─┬ Key: "one"
// │ └── "one"
// └─┬ Key: "two"
//   └── "two"
inspect(a);
// Object
// └─┬ Key: "one"
//   └── "one"

Inspecting inheritance chain (inherited properties)

var inspect = require('deep-inspect');
function Parent() {}
Parent.prototype.name = 'Parent';

function Child() {}
Child.prototype = Object.create(Parent.prototype);
Child.prototype.constructor = Child;

inspect(new Child(), {parentChainLevel: 4});
// Object
// └─┬ [[Parent]] : Object
//   ├─┬ [[Parent]] : Object
//   │ ├─┬ [[Parent]] : Object
//   │ │ └── [[Parent]] : null
//   │ └─┬ Key: "name"
//   │   └── "Parent"
//   └─┬ Key: "constructor"
//     └── [Function Child]

Keywords

nested

FAQs

Package last updated on 25 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.