introspect-fun

1.0.4 • Public • Published

introspect-fun

Node module that enables the introspection of a function to return its parameters' name in an array.

Installation

npm install --save introspect-fun

API

Basic usge

var introspect = require('introspect-fun');
var noArgs = function() {};
var withArgs = function(arg1, arg2, hello) {};
function withArgsBis (arg1, arg2, arg3) {};
function withNestedFunc (notNestedArg) {
    function myNested (nestedArg) {}
};
 
var res1 = introspect(noArgs);
// res1 = []
 
var res2 = introspect(withArgs);
// res2 = ['arg1', 'arg2', 'hello']
 
var res3 = introspect(withArgsBis);
// res3 = ['arg1', 'arg2', 'arg3']
 
var res4 = introspect(function(arg1){});
// res4 = ['arg1']
 
var res5 = introspect(withNestedFunc);
// res5 = ['notNestedArg']

ES6 Generator functions an arrow functions

Generator functions and arrow functions won't be a problem under --harmony flag

var introspect = require('introspect-fun');
 
var gen = function*(arg1, arg2) {};
 
var resGen = introspect(gen);
// resGen = ['arg1', 'arg2']
 
var resArrow = introspect(arg1 => arg1+1);
// resArrow = ['arg1']

Motivation

Inspired from

Run test

npm test

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.4
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.4
    1
  • 1.0.2
    1
  • 1.0.1
    1
  • 1.0.0
    1

Package Sidebar

Install

npm i introspect-fun

Weekly Downloads

4

Version

1.0.4

License

MIT

Last publish

Collaborators

  • nvargas