Skip to content

Instantly share code, notes, and snippets.

@wryk
Last active August 29, 2015 14:07
Show Gist options
  • Save wryk/206e259f67028d5ea6dc to your computer and use it in GitHub Desktop.
Save wryk/206e259f67028d5ea6dc to your computer and use it in GitHub Desktop.
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