_baseMatchesProperty.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import baseIsEqual from './_baseIsEqual.js';
  2. import get from './get.js';
  3. import hasIn from './hasIn.js';
  4. import isKey from './_isKey.js';
  5. import isStrictComparable from './_isStrictComparable.js';
  6. import matchesStrictComparable from './_matchesStrictComparable.js';
  7. import toKey from './_toKey.js';
  8. /** Used to compose bitmasks for value comparisons. */
  9. var COMPARE_PARTIAL_FLAG = 1,
  10. COMPARE_UNORDERED_FLAG = 2;
  11. /**
  12. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  13. *
  14. * @private
  15. * @param {string} path The path of the property to get.
  16. * @param {*} srcValue The value to match.
  17. * @returns {Function} Returns the new spec function.
  18. */
  19. function baseMatchesProperty(path, srcValue) {
  20. if (isKey(path) && isStrictComparable(srcValue)) {
  21. return matchesStrictComparable(toKey(path), srcValue);
  22. }
  23. return function(object) {
  24. var objValue = get(object, path);
  25. return (objValue === undefined && objValue === srcValue)
  26. ? hasIn(object, path)
  27. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  28. };
  29. }
  30. export default baseMatchesProperty;