baseIsMatch.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. var baseIsEqual = require('./baseIsEqual'),
  2. toObject = require('./toObject');
  3. /**
  4. * The base implementation of `_.isMatch` without support for callback
  5. * shorthands and `this` binding.
  6. *
  7. * @private
  8. * @param {Object} object The object to inspect.
  9. * @param {Array} matchData The propery names, values, and compare flags to match.
  10. * @param {Function} [customizer] The function to customize comparing objects.
  11. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  12. */
  13. function baseIsMatch(object, matchData, customizer) {
  14. var index = matchData.length,
  15. length = index,
  16. noCustomizer = !customizer;
  17. if (object == null) {
  18. return !length;
  19. }
  20. object = toObject(object);
  21. while (index--) {
  22. var data = matchData[index];
  23. if ((noCustomizer && data[2])
  24. ? data[1] !== object[data[0]]
  25. : !(data[0] in object)
  26. ) {
  27. return false;
  28. }
  29. }
  30. while (++index < length) {
  31. data = matchData[index];
  32. var key = data[0],
  33. objValue = object[key],
  34. srcValue = data[1];
  35. if (noCustomizer && data[2]) {
  36. if (objValue === undefined && !(key in object)) {
  37. return false;
  38. }
  39. } else {
  40. var result = customizer ? customizer(objValue, srcValue, key) : undefined;
  41. if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
  42. return false;
  43. }
  44. }
  45. }
  46. return true;
  47. }
  48. module.exports = baseIsMatch;