Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

inspect-property

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inspect-property

Inspects a Property and returns useful informations about it (e.g. nested properties, function inspection, property descriptor, value, type, constructor)

  • 0.0.5
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

inspect-property

Build Status

Inspects a Property and returns useful informations about it (e.g. nested properties, function inspection, property descriptor, value, type, constructor)

Installation

npm install inspect-property

Usage

inspectProperty(o, propertyName, { delimiter = '.', inspectFunction = true, inspectProperties = true, enumerability, inherited} = {} );

o: Object || Property || Value to be inspected.

propertyName: When passing as inspectProperty(parentObject, 'childPropertyName'), propertyDescriptor will be returned. Note that childPropertyName must be a string.

delimiter What will be used as a delimiter for the nested properties at properties keys. Default is ',' e.g. 'a.b.c'

inspectFunction If functions should be inspected. See inspect-function for details about the function inspection.

inspectProperties When set to false, properties will be a simple {key: value} object, without any inspection. The default value is true, returning {key: inspectProperty(value)}.

path An array representing the current property path. e.g. from the above example it will be [ 'a', 'b', 'c' ] for the 'c' property

parent The parent object of the current property. e.g. from the above example it will be the object { c: 'cValue' } for the 'c' property

enumerability: When inspecting nested properties, defines how it should look up regarding enumerability. The options are:

  • 'enumerable' (default)
  • 'nonenumerable'
  • 'all'

inherited: Determines if it should look up on the prototype chain when inspecting nested properties. The options are:

  • true (default)
  • false

Example

const inspectProperty = require('../');

const data = {
	a: {
		b: {
			c: (z = 'DefaultX', k) => z+k
		},
		d: 3,
		f: {
			g: 'h'
		}
	}
};

const result = inspectProperty(data);

// RESULT
// Below is a JSON.stringify(result), so functions references are ommitted
{
    "value": {
        "a": {
            "b": {},
            "d": 3,
            "f": {
                "g": "h"
            }
        }
    },
    "type": "object",
    "constructor": {
        "name": "Object"
    },
    "properties": {
        "a": {
            "value": {
                "b": {},
                "d": 3,
                "f": {
                    "g": "h"
                }
            },
            "type": "object",
            "constructor": {
                "name": "Object"
            }
        },
        "a.b": {
            "value": {},
            "type": "object",
            "constructor": {
                "name": "Object"
            }
        },
        "a.b.c": {
            "type": "function",
            "constructor": {
                "name": "Function"
            },
            "functionInspection": {
                "name": "c",
                "parameters": {
                    "expected": [
                        "z",
                        "k"
                    ],
                    "defaultValues": {
                        "z": "'DefaultX'"
                    },
                    "names": [
                        "z",
                        "k"
                    ],
                    "definitions": [
                        "z='DefaultX'",
                        "k"
                    ]
                },
                "signature": "c(z = 'DefaultX', k);"
            }
        },
        "a.d": {
            "value": 3,
            "type": "number",
            "constructor": {
                "name": "Number"
            }
        },
        "a.f": {
            "value": {
                "g": "h"
            },
            "type": "object",
            "constructor": {
                "name": "Object"
            }
        },
        "a.f.g": {
            "value": "h",
            "type": "string",
            "constructor": {
                "name": "String"
            }
        }
    }
}

Keywords

FAQs

Package last updated on 18 Jul 2017

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc