Skip to content

Get function arguments, useful for and used in dependency injectors. Works for regular functions, generator functions and arrow functions.

License

Notifications You must be signed in to change notification settings

tunnckoCore/function-arguments

Repository files navigation

function-arguments npm version github release License

Get arguments of a function, useful for and used in dependency injectors. Works for regular functions, generator functions and arrow functions.

code style linux build code coverage dependency status npm downloads paypal donate

Install

Install with npm

$ npm i function-arguments --save

Important: for more advanced stuff please use parse-function, don't suggest features or complex bugs.

Usage

For more use-cases see the tests

const functionArguments = require('function-arguments')

API

Get function arguments names.

Params

  • fn {Function}: Function from which to get arguments names.
  • returns {Array}

Example

var fnArgs = require('function-arguments')

console.log(fnArgs(function (a, b, c) {})) // => [ 'a', 'b', 'c' ]
console.log(fnArgs(function named (a , b, c) {})) // => [ 'a', 'b', 'c' ]

console.log(fnArgs(a => {})) // => [ 'a' ]
console.log(fnArgs((a, b) => {})) // => [ 'a', 'b' ]

console.log(fnArgs(function * (a ,b, c) {})) // => [ 'a', 'b', 'c' ]
console.log(fnArgs(function * named (a ,b, c) {})) // => [ 'a', 'b', 'c' ]

Works when using comments

As it works for ES2015, it also works if you use comments in weird places.

console.log(fnArgs(function /* something may */ (
  // go,
  go,
  /* wrong, */
  here
  // (when, using, comments) {}
) { return 1 })) // => [ 'go', 'here' ]

Related

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue. But before doing anything, please read the CONTRIBUTING.md guidelines.

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

About

Get function arguments, useful for and used in dependency injectors. Works for regular functions, generator functions and arrow functions.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks