_baseIteratee.js 895 B

1234567891011121314151617181920212223242526272829303132
  1. var baseMatches = require('./_baseMatches'),
  2. baseMatchesProperty = require('./_baseMatchesProperty'),
  3. identity = require('./identity'),
  4. isArray = require('./isArray'),
  5. property = require('./property');
  6. /**
  7. * The base implementation of `_.iteratee`.
  8. *
  9. * @private
  10. * @param {*} [value=_.identity] The value to convert to an iteratee.
  11. * @returns {Function} Returns the iteratee.
  12. */
  13. function baseIteratee(value) {
  14. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  15. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  16. if (typeof value == 'function') {
  17. return value;
  18. }
  19. if (value == null) {
  20. return identity;
  21. }
  22. if (typeof value == 'object') {
  23. return isArray(value)
  24. ? baseMatchesProperty(value[0], value[1])
  25. : baseMatches(value);
  26. }
  27. return property(value);
  28. }
  29. module.exports = baseIteratee;