isIterateeCall.js 895 B

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