source: node_modules/ramda-adjunct/lib/invokeArgs.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _ramda = require("ramda");
6var _isNotFunction = _interopRequireDefault(require("./isNotFunction"));
7var _isEmptyArray = _interopRequireDefault(require("./isEmptyArray"));
8function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9/**
10 * Invokes the method at path of object with given arguments.
11 *
12 * @func invokeArgs
13 * @memberOf RA
14 * @since {@link https://char0n.github.io/ramda-adjunct/2.27.0|v2.27.0}
15 * @category Object
16 * @sig Array -> Array -> Object -> *
17 * @param {Array.<string|number>} path The path of the method to invoke
18 * @param {Array} args The arguments to invoke the method with
19 * @param {Object} obj The object to query
20 * @return {*}
21 * @example
22 *
23 * RA.invokeArgs(['abs'], [-1], Math); //=> 1
24 * RA.invokeArgs(['path', 'to', 'non-existent', 'method'], [-1], Math); //=> undefined
25 */
26
27var invokeArgs = (0, _ramda.curryN)(3, function (mpath, args, obj) {
28 var method = (0, _ramda.path)(mpath, obj);
29 var context = (0, _ramda.path)((0, _ramda.init)(mpath), obj);
30 if ((0, _isNotFunction["default"])(method)) return undefined;
31 if ((0, _isEmptyArray["default"])(mpath)) return undefined;
32 var boundMethod = (0, _ramda.bind)(method, context);
33 return (0, _ramda.apply)(boundMethod, args);
34});
35var _default = invokeArgs;
36exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.