matchesProperty.js 924 B

1234567891011121314151617181920212223242526272829303132
  1. var baseClone = require('./_baseClone'),
  2. baseMatchesProperty = require('./_baseMatchesProperty');
  3. /**
  4. * Creates a function that performs a partial deep comparison between the
  5. * value at `path` of a given object to `srcValue`, returning `true` if the
  6. * object value is equivalent, else `false`.
  7. *
  8. * **Note:** This method supports comparing the same values as `_.isEqual`.
  9. *
  10. * @static
  11. * @memberOf _
  12. * @since 3.2.0
  13. * @category Util
  14. * @param {Array|string} path The path of the property to get.
  15. * @param {*} srcValue The value to match.
  16. * @returns {Function} Returns the new spec function.
  17. * @example
  18. *
  19. * var users = [
  20. * { 'user': 'barney' },
  21. * { 'user': 'fred' }
  22. * ];
  23. *
  24. * _.find(users, _.matchesProperty('user', 'fred'));
  25. * // => { 'user': 'fred' }
  26. */
  27. function matchesProperty(path, srcValue) {
  28. return baseMatchesProperty(path, baseClone(srcValue, true));
  29. }
  30. module.exports = matchesProperty;