Skip to content

Instantly share code, notes, and snippets.

@samthor
Last active November 11, 2024 07:16
Show Gist options
  • Save samthor/a48c38a31715e9fdda3310a4e2a17ccf to your computer and use it in GitHub Desktop.
Save samthor/a48c38a31715e9fdda3310a4e2a17ccf to your computer and use it in GitHub Desktop.
const functionMatch = /^function\s*\w*\(([\w\s,]+)\) {/;
/**
* @param {!Function} fn
* @return {!Array<string>} array of simple arg names (no =, ... etc)
*/
function simpleArgNames(fn) {
const match = functionRe.exec(fn.toString());
if (!match) { return []; }
const args = match[1].split(',').map((x) => x.trim());
if (args.length && args[args.length - 1] === '') {
args.pop();
}
return args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment