matchesProperty.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. var baseClone = require('./_baseClone'),
  2. baseMatchesProperty = require('./_baseMatchesProperty');
  3. /** Used to compose bitmasks for cloning. */
  4. var CLONE_DEEP_FLAG = 1;
  5. /**
  6. * Creates a function that performs a partial deep comparison between the
  7. * value at `path` of a given object to `srcValue`, returning `true` if the
  8. * object value is equivalent, else `false`.
  9. *
  10. * **Note:** Partial comparisons will match empty array and empty object
  11. * `srcValue` values against any array or object value, respectively. See
  12. * `_.isEqual` for a list of supported value comparisons.
  13. *
  14. * @static
  15. * @memberOf _
  16. * @since 3.2.0
  17. * @category Util
  18. * @param {Array|string} path The path of the property to get.
  19. * @param {*} srcValue The value to match.
  20. * @returns {Function} Returns the new spec function.
  21. * @example
  22. *
  23. * var objects = [
  24. * { 'a': 1, 'b': 2, 'c': 3 },
  25. * { 'a': 4, 'b': 5, 'c': 6 }
  26. * ];
  27. *
  28. * _.find(objects, _.matchesProperty('a', 4));
  29. * // => { 'a': 4, 'b': 5, 'c': 6 }
  30. */
  31. function matchesProperty(path, srcValue) {
  32. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  33. }
  34. module.exports = matchesProperty;