mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 17:37:50 +00:00
Bump to v4.0.0.
This commit is contained in:
41
iteratee.js
Normal file
41
iteratee.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import baseIteratee from './internal/baseIteratee';
|
||||
import isArray from './isArray';
|
||||
import isObjectLike from './isObjectLike';
|
||||
import matches from './matches';
|
||||
|
||||
/**
|
||||
* Creates a function that invokes `func` with the arguments of the created
|
||||
* function. If `func` is a property name the created callback returns the
|
||||
* property value for a given element. If `func` is an object the created
|
||||
* callback returns `true` for elements that contain the equivalent object properties, otherwise it returns `false`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Util
|
||||
* @param {*} [func=_.identity] The value to convert to a callback.
|
||||
* @returns {Function} Returns the callback.
|
||||
* @example
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'barney', 'age': 36 },
|
||||
* { 'user': 'fred', 'age': 40 }
|
||||
* ];
|
||||
*
|
||||
* // create custom iteratee shorthands
|
||||
* _.iteratee = _.wrap(_.iteratee, function(callback, func) {
|
||||
* var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func);
|
||||
* return !p ? callback(func) : function(object) {
|
||||
* return (p[2] == '>' ? object[p[1]] > p[3] : object[p[1]] < p[3]);
|
||||
* };
|
||||
* });
|
||||
*
|
||||
* _.filter(users, 'age > 36');
|
||||
* // => [{ 'user': 'fred', 'age': 40 }]
|
||||
*/
|
||||
function iteratee(func) {
|
||||
return (isObjectLike(func) && !isArray(func))
|
||||
? matches(func)
|
||||
: baseIteratee(func);
|
||||
}
|
||||
|
||||
export default iteratee;
|
||||
Reference in New Issue
Block a user