matchesProperty.js 957 B

1234567891011121314151617181920212223242526272829303132
  1. var baseClone = require('../internal/baseClone'),
  2. baseMatchesProperty = require('../internal/baseMatchesProperty');
  3. /**
  4. * Creates a function that compares the property value of `path` on a given
  5. * object to `value`.
  6. *
  7. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  8. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  9. * their own, not inherited, enumerable properties.
  10. *
  11. * @static
  12. * @memberOf _
  13. * @category Utility
  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 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;