matches.js 1006 B

1234567891011121314151617181920212223242526272829303132
  1. var baseClone = require('./_baseClone'),
  2. baseMatches = require('./_baseMatches');
  3. /**
  4. * Creates a function that performs a partial deep comparison between a given
  5. * object and `source`, returning `true` if the given object has equivalent
  6. * property values, else `false`. The created function is equivalent to
  7. * `_.isMatch` with a `source` partially applied.
  8. *
  9. * **Note:** This method supports comparing the same values as `_.isEqual`.
  10. *
  11. * @static
  12. * @memberOf _
  13. * @since 3.0.0
  14. * @category Util
  15. * @param {Object} source The object of property values to match.
  16. * @returns {Function} Returns the new spec function.
  17. * @example
  18. *
  19. * var users = [
  20. * { 'user': 'barney', 'age': 36, 'active': true },
  21. * { 'user': 'fred', 'age': 40, 'active': false }
  22. * ];
  23. *
  24. * _.filter(users, _.matches({ 'age': 40, 'active': false }));
  25. * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
  26. */
  27. function matches(source) {
  28. return baseMatches(baseClone(source, true));
  29. }
  30. module.exports = matches;