matches.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. var baseClone = require('../internal/baseClone'),
  2. baseMatches = require('../internal/baseMatches');
  3. /**
  4. * Creates a function that performs a deep comparison between a given object
  5. * and `source`, returning `true` if the given object has equivalent property
  6. * values, else `false`.
  7. *
  8. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  9. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  10. * their own, not inherited, enumerable properties. For comparing a single
  11. * own or inherited property value see `_.matchesProperty`.
  12. *
  13. * @static
  14. * @memberOf _
  15. * @category Utility
  16. * @param {Object} source The object of property values to match.
  17. * @returns {Function} Returns the new function.
  18. * @example
  19. *
  20. * var users = [
  21. * { 'user': 'barney', 'age': 36, 'active': true },
  22. * { 'user': 'fred', 'age': 40, 'active': false }
  23. * ];
  24. *
  25. * _.filter(users, _.matches({ 'age': 40, 'active': false }));
  26. * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
  27. */
  28. function matches(source) {
  29. return baseMatches(baseClone(source, true));
  30. }
  31. module.exports = matches;