1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports["default"] = void 0;
|
---|
5 | var _ramda = require("ramda");
|
---|
6 | var _isNotFunction = _interopRequireDefault(require("./isNotFunction"));
|
---|
7 | var _isEmptyArray = _interopRequireDefault(require("./isEmptyArray"));
|
---|
8 | function _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 |
|
---|
27 | var 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 | });
|
---|
35 | var _default = invokeArgs;
|
---|
36 | exports["default"] = _default; |
---|