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