function-arguments
Get arguments of a function, useful for and used in dependency injectors. Works for regular functions, generator functions and arrow functions.
Last updated 9 years ago by tunnckocore .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install function-arguments 
SYNC missed versions from official npm registry.

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

functionArguments

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.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

Current Tags

  • 1.0.9                                ...           latest (5 years ago)

11 Versions

  • 1.0.9                                ...           5 years ago
  • 1.0.8                                ...           8 years ago
  • 1.0.7                                ...           8 years ago
  • 1.0.6                                ...           8 years ago
  • 1.0.5                                ...           8 years ago
  • 1.0.4                                ...           9 years ago
  • 1.0.3                                ...           9 years ago
  • 1.0.2                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
  • 0.0.0                                ...           9 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (2)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |