mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
Expose _.unary.
This commit is contained in:
47
lodash.js
47
lodash.js
@@ -847,6 +847,13 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base implementation of `_.unary` without support for storing wrapper metadata.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Function} func The function to cap arguments for.
|
||||||
|
* @returns {Function} Returns the new function.
|
||||||
|
*/
|
||||||
function baseUnary(func) {
|
function baseUnary(func) {
|
||||||
return function(value) {
|
return function(value) {
|
||||||
return func(value);
|
return func(value);
|
||||||
@@ -1466,10 +1473,10 @@
|
|||||||
* `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`, `slice`, `sort`,
|
* `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`, `slice`, `sort`,
|
||||||
* `sortBy`, `sortByOrder`, `splice`, `spread`, `tail`, `take`, `takeRight`,
|
* `sortBy`, `sortByOrder`, `splice`, `spread`, `tail`, `take`, `takeRight`,
|
||||||
* `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`,
|
* `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`,
|
||||||
* `toPath`, `toPlainObject`, `transform`, `union`, `unionBy`, `unionWith`,
|
* `toPath`, `toPlainObject`, `transform`, `unary`, `union`, `unionBy`,
|
||||||
* `uniq`, `uniqBy`, `uniqWith`, `unset`, `unshift`, `unzip`, `unzipWith`,
|
* `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, `unshift`, `unzip`,
|
||||||
* `values`, `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
|
* `unzipWith`, `values`, `valuesIn`, `without`, `wrap`, `xor`, `xorBy`,
|
||||||
* `zipObject`, and `zipWith`
|
* `xorWith`, `zip`, `zipObject`, and `zipWith`
|
||||||
*
|
*
|
||||||
* The wrapper methods that are **not** chainable by default are:
|
* The wrapper methods that are **not** chainable by default are:
|
||||||
* `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
|
* `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
|
||||||
@@ -1488,9 +1495,10 @@
|
|||||||
* `reduce`, `reduceRight`, `repeat`, `result`, `round`, `runInContext`,
|
* `reduce`, `reduceRight`, `repeat`, `result`, `round`, `runInContext`,
|
||||||
* `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`,
|
* `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`,
|
||||||
* `sortedLastIndex`, `sortedLastIndexBy`, `startCase`, `startsWith`, `sum`,
|
* `sortedLastIndex`, `sortedLastIndexBy`, `startCase`, `startsWith`, `sum`,
|
||||||
* `sumBy`, `template`, `toLower`, `toInteger`, `toLength`, `toSafeInteger`,
|
* `sumBy`, `template`, `toLower`, `toInteger`, `toLength`, `toNumber`,
|
||||||
* `toString`, `toUpper`, `trim`, `trimLeft`, `trimRight`, `truncate`,
|
* `toSafeInteger`, toString`, `toUpper`, `trim`, `trimLeft`, `trimRight`,
|
||||||
* `unescape`, `uniqueId`, `upperCase`, `upperFirst`, `value`, and `words`
|
* `truncate`, `unescape`, `uniqueId`, `upperCase`, `upperFirst`, `value`,
|
||||||
|
* and `words`
|
||||||
*
|
*
|
||||||
* @name _
|
* @name _
|
||||||
* @constructor
|
* @constructor
|
||||||
@@ -7779,7 +7787,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that accepts up to `n` arguments ignoring any
|
* Creates a function that accepts up to `n` arguments, ignoring any
|
||||||
* additional arguments.
|
* additional arguments.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
@@ -8720,6 +8728,24 @@
|
|||||||
return debounce(func, wait, { 'leading': leading, 'maxWait': +wait, 'trailing': trailing });
|
return debounce(func, wait, { 'leading': leading, 'maxWait': +wait, 'trailing': trailing });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a function that accepts up to one argument, ignoring any
|
||||||
|
* additional arguments.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Function
|
||||||
|
* @param {Function} func The function to cap arguments for.
|
||||||
|
* @returns {Function} Returns the new function.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* _.map(['6', '8', '10'], _.unary(parseInt));
|
||||||
|
* // => [6, 8, 10]
|
||||||
|
*/
|
||||||
|
function unary(func) {
|
||||||
|
return ary(func, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that provides `value` to the wrapper function as its
|
* Creates a function that provides `value` to the wrapper function as its
|
||||||
* first argument. Any additional arguments provided to the function are
|
* first argument. Any additional arguments provided to the function are
|
||||||
@@ -8746,10 +8772,6 @@
|
|||||||
return partial(wrapper, value);
|
return partial(wrapper, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function unary(func) {
|
|
||||||
return ary(func, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13411,6 +13433,7 @@
|
|||||||
lodash.toPath = toPath;
|
lodash.toPath = toPath;
|
||||||
lodash.toPlainObject = toPlainObject;
|
lodash.toPlainObject = toPlainObject;
|
||||||
lodash.transform = transform;
|
lodash.transform = transform;
|
||||||
|
lodash.unary = unary;
|
||||||
lodash.union = union;
|
lodash.union = union;
|
||||||
lodash.unionBy = unionBy;
|
lodash.unionBy = unionBy;
|
||||||
lodash.unionWith = unionWith;
|
lodash.unionWith = unionWith;
|
||||||
|
|||||||
@@ -22190,7 +22190,8 @@
|
|||||||
'rearg',
|
'rearg',
|
||||||
'rest',
|
'rest',
|
||||||
'spread',
|
'spread',
|
||||||
'throttle'
|
'throttle',
|
||||||
|
'unary'
|
||||||
];
|
];
|
||||||
|
|
||||||
var noBinding = [
|
var noBinding = [
|
||||||
@@ -22318,7 +22319,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should throw an error for falsey arguments', function(assert) {
|
QUnit.test('should throw an error for falsey arguments', function(assert) {
|
||||||
assert.expect(23);
|
assert.expect(24);
|
||||||
|
|
||||||
lodashStable.each(rejectFalsey, function(methodName) {
|
lodashStable.each(rejectFalsey, function(methodName) {
|
||||||
var expected = lodashStable.map(falsey, lodashStable.constant(true)),
|
var expected = lodashStable.map(falsey, lodashStable.constant(true)),
|
||||||
|
|||||||
Reference in New Issue
Block a user