forked from lodash/lodash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ary.js
28 lines (25 loc) · 845 Bytes
/
ary.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import createWrap from './.internal/createWrap.js';
/** Used to compose bitmasks for function metadata. */
const WRAP_ARY_FLAG = 128;
/**
* Creates a function that invokes `func`, with up to `n` arguments,
* ignoring any additional arguments.
*
* @static
* @since 3.0.0
* @category Function
* @param {Function} func The function to cap arguments for.
* @param {number} [n=func.length] The arity cap.
* @param- {Object} [guard] Enables use as an iteratee for methods like `map`.
* @returns {Function} Returns the new capped function.
* @example
*
* map(['6', '8', '10'], ary(parseInt, 1));
* // => [6, 8, 10]
*/
function ary(func, n, guard) {
n = guard ? undefined : n;
n = (func && n == null) ? func.length : n;
return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
}
export default ary;