Last active
August 29, 2015 14:07
-
-
Save wryk/206e259f67028d5ea6dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default getFunctionArguments | |
var COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg | |
var ARGUMENTS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m | |
var COMMA = /,/ | |
/* | |
* @param {Function} fn | |
* @return {Array<String>} | |
**/ | |
function getFunctionArguments (fn) { | |
switch (fn.length) { | |
case 0: return [] | |
default: | |
return fn | |
.toString() | |
.replace(COMMENTS, '') | |
.match(ARGUMENTS)[1] | |
.split(COMMA) | |
.map(trim) | |
} | |
} | |
/** | |
* @param {String} it | |
* @return {String} | |
**/ | |
function trim (it) { | |
return it.trim() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment