@alesmenzel/function-arguments
v1.1.0
Published
Parse function arguments
Readme
Function arguments
Parses function arguments and returns an array of parameter names. Uses AST parser acorn and can handle functions with default parameters.
Instalation
npm i @alesmenzel/function-argumentsUsage
Can parse ES5 named and unamed functions as well as ES6 arrow funtions and shorthand arrow functions.
const functionArguments = require('@alesmenzel/function-arguments');
// ES5
const subject = function x(a, b, c) {};
functionArguments(subject);
// ["a", "b", "c"]
// ES6
const subject = (a, b = 15, c) => {};
functionArguments(subject);
// ["a", "b", "c"]
// ES6 shorthand
const subject = a => a;
functionArguments(subject);
// ["a"]