react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / utility / callback.js
80742 viewsvar baseCallback = require('../internal/baseCallback'),1isIterateeCall = require('../internal/isIterateeCall'),2isObjectLike = require('../internal/isObjectLike'),3matches = require('./matches');45/**6* Creates a function that invokes `func` with the `this` binding of `thisArg`7* and arguments of the created function. If `func` is a property name the8* created callback returns the property value for a given element. If `func`9* is an object the created callback returns `true` for elements that contain10* the equivalent object properties, otherwise it returns `false`.11*12* @static13* @memberOf _14* @alias iteratee15* @category Utility16* @param {*} [func=_.identity] The value to convert to a callback.17* @param {*} [thisArg] The `this` binding of `func`.18* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.19* @returns {Function} Returns the callback.20* @example21*22* var users = [23* { 'user': 'barney', 'age': 36 },24* { 'user': 'fred', 'age': 40 }25* ];26*27* // wrap to create custom callback shorthands28* _.callback = _.wrap(_.callback, function(callback, func, thisArg) {29* var match = /^(.+?)__([gl]t)(.+)$/.exec(func);30* if (!match) {31* return callback(func, thisArg);32* }33* return function(object) {34* return match[2] == 'gt'35* ? object[match[1]] > match[3]36* : object[match[1]] < match[3];37* };38* });39*40* _.filter(users, 'age__gt36');41* // => [{ 'user': 'fred', 'age': 40 }]42*/43function callback(func, thisArg, guard) {44if (guard && isIterateeCall(func, thisArg, guard)) {45thisArg = null;46}47return isObjectLike(func)48? matches(func)49: baseCallback(func, thisArg);50}5152module.exports = callback;535455