- 1 :
/* eslint-disable @typescript-eslint/no-unused-vars */
- 2 :
/**
- 3 :
* Get all method from class
- 4 :
* @param toCheck
- 5 :
* @returns
- 6 :
*/
- 7 :
const getAllMethods = function (toCheck: { [key: string]: any }) {
- 8 :
if (!toCheck) return [];
- 9 :
try {
- 10 :
const props = [];
- 11 :
let obj = toCheck;
- 12 :
do {
- 13 :
props.push(...Object.getOwnPropertyNames(obj));
- 14 :
} while ((obj = Object.getPrototypeOf(obj)));
- 15 :
return props
- 16 :
.sort()
- 17 :
.filter((e, i, arr_fname) => {
- 18 :
const c: ClassDecorator = toCheck[e];
- 19 :
const fname = arr_fname[i + 1];
- 20 :
if (e != fname && typeof c == 'function') return true;
- 21 :
})
- 22 :
.filter((fname) => {
- 23 :
return ![
- 24 :
'__defineGetter__',
- 25 :
'__defineSetter__',
- 26 :
'__lookupGetter__',
- 27 :
'__lookupSetter__',
- 28 :
'constructor',
- 29 :
'hasOwnProperty',
- 30 :
'isPrototypeOf',
- 31 :
'propertyIsEnumerable',
- 32 :
'toLocaleString',
- 33 :
'toString',
- 34 :
'valueOf',
- 35 :
].includes(fname);
- 36 :
});
- 37 :
} catch (e) {
- 38 :
return Object.getOwnPropertyNames(toCheck).filter((prop) => typeof toCheck[prop] === 'function');
- 39 :
}
- 40 :
};