isMatch.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var baseIsMatch = require('../internal/baseIsMatch'),
  2. bindCallback = require('../internal/bindCallback'),
  3. getMatchData = require('../internal/getMatchData');
  4. /**
  5. * Performs a deep comparison between `object` and `source` to determine if
  6. * `object` contains equivalent property values. If `customizer` is provided
  7. * it's invoked to compare values. If `customizer` returns `undefined`
  8. * comparisons are handled by the method instead. The `customizer` is bound
  9. * to `thisArg` and invoked with three arguments: (value, other, index|key).
  10. *
  11. * **Note:** This method supports comparing properties of arrays, booleans,
  12. * `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
  13. * and DOM nodes are **not** supported. Provide a customizer function to extend
  14. * support for comparing other values.
  15. *
  16. * @static
  17. * @memberOf _
  18. * @category Lang
  19. * @param {Object} object The object to inspect.
  20. * @param {Object} source The object of property values to match.
  21. * @param {Function} [customizer] The function to customize value comparisons.
  22. * @param {*} [thisArg] The `this` binding of `customizer`.
  23. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  24. * @example
  25. *
  26. * var object = { 'user': 'fred', 'age': 40 };
  27. *
  28. * _.isMatch(object, { 'age': 40 });
  29. * // => true
  30. *
  31. * _.isMatch(object, { 'age': 36 });
  32. * // => false
  33. *
  34. * // using a customizer callback
  35. * var object = { 'greeting': 'hello' };
  36. * var source = { 'greeting': 'hi' };
  37. *
  38. * _.isMatch(object, source, function(value, other) {
  39. * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
  40. * });
  41. * // => true
  42. */
  43. function isMatch(object, source, customizer, thisArg) {
  44. customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
  45. return baseIsMatch(object, getMatchData(source), customizer);
  46. }
  47. module.exports = isMatch;