Last active
March 16, 2018 05:56
-
-
Save sms-system/fd33604fb5aee74fadddc085d12939f9 to your computer and use it in GitHub Desktop.
Get function argument names
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
Object.defineProperty(Function.prototype, 'args', { | |
get () { | |
return this | |
.toString() | |
.replace(/\/\/.*$/mg,'') // COMMENT | |
.replace(/\/\*.*?\*\//g, '') // COMMENT | |
.replace(/\/.*?(?<!\\)\//g, '') // REGEXP | |
.replace(/'.*?(?<!\\)'/g, '') //STRING | |
.replace(/\s+/g,'') | |
.split(')')[0] | |
.split('(')[1] | |
.split(',') | |
.filter(a => !a.startsWith('...') && a !== '') | |
.map(a => a.split('=')[0]) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment