Files
Plastic-Raspi-5/node_modules/object-to-arguments/node_modules/inspect-function/README.md

1.3 KiB

inspect-function

Build Status

Inspects a function and returns informations about it (e.g. name, parameters names, parameters and default values, signature). Useful when creating automated tasks, e.g., docs generations.

Installation

npm install inspect-function

Usage

inspectFunction(fn, name);

// The module
const inspectFunction = require('inspect-function');

// Just a function to test
const testFunction = (a = 'z', b = [1,2,3], c, {d,e: {f}, g} = {}) => console.log('noop');

// Inspects
const result = inspectFunction(testFunction);

// `result` will be:
{
    // If the second param, `name`, is passed in,
    // it will be the value of "name" here
	"name": "testFunction",
	"parameters": {
		"expected": [
			"a",
			"b",
			"c",
			"{d,e:{f},g}"
		],
		"defaultValues": {
			"a": "'z'",
			"b": "[1,2,3]",
			"{d,e:{f},g}": "{}"
		},

		// Note that `"names"` contains also
		// The parameters names after Destructuring
		"names": [
			"a",
			"b",
			"c",
			"d",
			"f",
			"g"
		],
		"definitions": [
			"a='z'",
			"b=[1,2,3]",
			"c",
			"{d,e:{f},g}={}"
		]
	},
	"signature": "testFunction(a = 'z', b = [1,2,3], c, {d,e:{f},g} = {});"
}