xag / ui /src /utils /extract-args.ts
ddoc's picture
Upload 51 files
6242a59
raw
history blame contribute delete
459 Bytes
export const extractArgs = (func: (...args: any[]) => any) => {
return (func + '')
.replace(/[/][/].*$/gm, '') // 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 [""]
};