isIterateeCall.js 853 B

12345678910111213141516171819202122232425262728
  1. import eq from '../eq';
  2. import isArrayLike from '../isArrayLike';
  3. import isIndex from './isIndex';
  4. import isObject from '../isObject';
  5. /**
  6. * Checks if the provided arguments are from an iteratee call.
  7. *
  8. * @private
  9. * @param {*} value The potential iteratee value argument.
  10. * @param {*} index The potential iteratee index or key argument.
  11. * @param {*} object The potential iteratee object argument.
  12. * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
  13. */
  14. function isIterateeCall(value, index, object) {
  15. if (!isObject(object)) {
  16. return false;
  17. }
  18. var type = typeof index;
  19. if (type == 'number'
  20. ? (isArrayLike(object) && isIndex(index, object.length))
  21. : (type == 'string' && index in object)) {
  22. return eq(object[index], value);
  23. }
  24. return false;
  25. }
  26. export default isIterateeCall;