function getParams(func) {
let str = func.toString();
str = str.replace(/\/\*[\s\S]*?\*\
.replace(/\/\/(.)*/g, '')
.replace(/{[\s\S]*}/, '')
.replace(/=>/g, '')
.trim();
let start = str.indexOf("(") + 1;
let end = str.length - 1;
let result = str.substring(start, end).split(", ");
let params = [];
result.forEach(element => {
element = element.replace(/=[\s\S]*/g, '').trim();
if (element.length > 0)
params.push(element);
});
return params;
}
let fun1 = function (a) { };
function fun2(a = 5 * 6 / 3,
b) { };
let fun3 = (a,
b,
c) => { };
console.log(`List of parameters of ${fun1.name}:`,
getParams(fun1));
console.log(`List of parameters of ${fun2.name}:`,
getParams(fun2));
console.log(`List of parameters of ${fun3.name}:`,
getParams(fun3));