UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

34 lines (33 loc) 855 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.method = void 0; const invoke_1 = require("./invoke"); /** * Creates a function that invokes the method at `path` of a given object. * Any additional arguments are provided to the invoked method. * * @since 5.11.0 * @category Util * @param path The path of the method to invoke. * @param args The arguments to invoke the method with. * @returns Returns the new invoker function. * @example * * ```js * const objects = [ * { 'a': { 'b': () => 2 } }, * { 'a': { 'b': () => 1 } } * ] * * map(objects, method('a.b')) * // => [2, 1] * * map(objects, method(['a', 'b'])) * // => [2, 1] * ``` */ function method(path, ...args) { return (object) => (0, invoke_1.invoke)(object, path, ...args); } exports.method = method; exports.default = method;