UNPKG

@sprucelabs/spruce-skill-utils

Version:

Loosely coupled classes and functions to make skill development faster! 🏎

30 lines (29 loc) 931 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.functionDelegationUtil = void 0; exports.functionDelegationUtil = { getAllFuncs(toCheck) { const props = []; let obj = toCheck; do { props.push(...Object.getOwnPropertyNames(obj)); } while ((obj = Object.getPrototypeOf(obj))); return props.sort().filter((e, i, arr) => { return e != arr[i + 1] && typeof toCheck[e] == 'function'; }); }, delegateFunctionCalls(from, to) { const props = this.getAllFuncs(to); for (const prop of props) { //@ts-ignore if (!from[prop]) { //@ts-ignore from[prop] = (...args) => { //@ts-ignore return to[prop](...args); }; } } }, }; exports.default = exports.functionDelegationUtil;