UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

43 lines (42 loc) 1.32 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.methodOf = void 0; const baseRest_1 = __importDefault(require("./.internal/baseRest")); const baseInvoke_1 = __importDefault(require("./.internal/baseInvoke")); /** * @ignore */ const internalMethodOf = (0, baseRest_1.default)((object, args) => function (path) { return (0, baseInvoke_1.default)(object, path, args); }); /** * The opposite of `method` this method creates a function that invokes * the method at a given path of `object`. Any additional arguments are * provided to the invoked method. * * @since 5.12.0 * @category Util * @param object The object to query. * @param args The arguments to invoke the method with. * @returns Returns the new invoker function. * @example * * ```js * const array = times(3, i => () => i) * const object = { 'a': array, 'b': array, 'c': array } * * map(['a[2]', 'c[0]'], methodOf(object)) * // => [2, 0] * * map([['a', '2'], ['c', '0']], methodOf(object)) * // => [2, 0] * ``` */ function methodOf(object, ...args) { return internalMethodOf(object, ...args); } exports.methodOf = methodOf; exports.default = methodOf;