import type { MethodPath, Methods } from './types.js'; import { isFunction, isObject } from './guards.js'; export const getMethodAtMethodPath = ( methodPath: MethodPath, methods: Methods, ): Function | undefined => { const result = methodPath.reduce( (acc, pathSegment) => { if (!isObject(acc) || !Object.hasOwn(acc, pathSegment)) { return undefined; } return acc[pathSegment]; }, methods, ); return isFunction(result) ? result : undefined; }; export const formatMethodPath = (methodPath: MethodPath): string => { return methodPath.join('.'); };