Last active
May 30, 2020 02:09
-
-
Save DavidWells/67976a2e59958672d135e2f8c41f3868 to your computer and use it in GitHub Desktop.
getFunctionArgsByName will return the argument key names. Careful using with minification
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
function getFunctionArgsByName(func) { | |
return (func + '') | |
.replace(/[/][/].*$/mg,'') // strip single-line comments | |
.replace(/\s+/g, '') // strip white space | |
.replace(/[/][*][^/*]*[*][/]/g, '') // strip multi-line comments | |
.split('){', 1)[0].replace(/^[^(]*[(]/, '') // extract the parameters | |
.replace(/=[^,]+/g, '') // strip any ES6 defaults | |
.split(',').filter(Boolean); // split & filter [""] | |
} | |
function xyz(lol, hi, cool) { | |
// stuff | |
} | |
const theArgs = getFunctionArgsByName(xyz) | |
// ['lol', 'hi', 'cool'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment