mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
821 B
29 lines
821 B
9 years ago
|
var createWrapper = require('./_createWrapper');
|
||
10 years ago
|
|
||
|
/** Used to compose bitmasks for wrapper metadata. */
|
||
|
var ARY_FLAG = 128;
|
||
|
|
||
|
/**
|
||
9 years ago
|
* Creates a function that accepts up to `n` arguments, ignoring any
|
||
10 years ago
|
* additional arguments.
|
||
|
*
|
||
|
* @static
|
||
|
* @memberOf _
|
||
|
* @category Function
|
||
|
* @param {Function} func The function to cap arguments for.
|
||
|
* @param {number} [n=func.length] The arity cap.
|
||
9 years ago
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
|
||
10 years ago
|
* @returns {Function} Returns the new function.
|
||
|
* @example
|
||
|
*
|
||
|
* _.map(['6', '8', '10'], _.ary(parseInt, 1));
|
||
|
* // => [6, 8, 10]
|
||
|
*/
|
||
|
function ary(func, n, guard) {
|
||
9 years ago
|
n = guard ? undefined : n;
|
||
|
n = (func && n == null) ? func.length : n;
|
||
9 years ago
|
return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
|
||
10 years ago
|
}
|
||
|
|
||
|
module.exports = ary;
|