source: node_modules/ramda-adjunct/es/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.0 KB
RevLine 
[d24f17c]1import { curryN, path, apply, init, bind } from 'ramda';
2import isNotFunction from './isNotFunction';
3import isEmptyArray from './isEmptyArray';
4
5/**
6 * Invokes the method at path of object with given arguments.
7 *
8 * @func invokeArgs
9 * @memberOf RA
10 * @since {@link https://char0n.github.io/ramda-adjunct/2.27.0|v2.27.0}
11 * @category Object
12 * @sig Array -> Array -> Object -> *
13 * @param {Array.<string|number>} path The path of the method to invoke
14 * @param {Array} args The arguments to invoke the method with
15 * @param {Object} obj The object to query
16 * @return {*}
17 * @example
18 *
19 * RA.invokeArgs(['abs'], [-1], Math); //=> 1
20 * RA.invokeArgs(['path', 'to', 'non-existent', 'method'], [-1], Math); //=> undefined
21 */
22
23var invokeArgs = curryN(3, function (mpath, args, obj) {
24 var method = path(mpath, obj);
25 var context = path(init(mpath), obj);
26 if (isNotFunction(method)) return undefined;
27 if (isEmptyArray(mpath)) return undefined;
28 var boundMethod = bind(method, context);
29 return apply(boundMethod, args);
30});
31export default invokeArgs;
Note: See TracBrowser for help on using the repository browser.