您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

_baseIsMatch.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. var Stack = require('./_Stack'),
  2. baseIsEqual = require('./_baseIsEqual');
  3. /** Used to compose bitmasks for value comparisons. */
  4. var COMPARE_PARTIAL_FLAG = 1,
  5. COMPARE_UNORDERED_FLAG = 2;
  6. /**
  7. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  8. *
  9. * @private
  10. * @param {Object} object The object to inspect.
  11. * @param {Object} source The object of property values to match.
  12. * @param {Array} matchData The property names, values, and compare flags to match.
  13. * @param {Function} [customizer] The function to customize comparisons.
  14. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  15. */
  16. function baseIsMatch(object, source, matchData, customizer) {
  17. var index = matchData.length,
  18. length = index,
  19. noCustomizer = !customizer;
  20. if (object == null) {
  21. return !length;
  22. }
  23. object = Object(object);
  24. while (index--) {
  25. var data = matchData[index];
  26. if ((noCustomizer && data[2])
  27. ? data[1] !== object[data[0]]
  28. : !(data[0] in object)
  29. ) {
  30. return false;
  31. }
  32. }
  33. while (++index < length) {
  34. data = matchData[index];
  35. var key = data[0],
  36. objValue = object[key],
  37. srcValue = data[1];
  38. if (noCustomizer && data[2]) {
  39. if (objValue === undefined && !(key in object)) {
  40. return false;
  41. }
  42. } else {
  43. var stack = new Stack;
  44. if (customizer) {
  45. var result = customizer(objValue, srcValue, key, object, source, stack);
  46. }
  47. if (!(result === undefined
  48. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  49. : result
  50. )) {
  51. return false;
  52. }
  53. }
  54. }
  55. return true;
  56. }
  57. module.exports = baseIsMatch;