baseMatches.js 824 B

123456789101112131415161718192021222324252627282930
  1. var baseIsMatch = require('./baseIsMatch'),
  2. getMatchData = require('./getMatchData'),
  3. toObject = require('./toObject');
  4. /**
  5. * The base implementation of `_.matches` which does not clone `source`.
  6. *
  7. * @private
  8. * @param {Object} source The object of property values to match.
  9. * @returns {Function} Returns the new function.
  10. */
  11. function baseMatches(source) {
  12. var matchData = getMatchData(source);
  13. if (matchData.length == 1 && matchData[0][2]) {
  14. var key = matchData[0][0],
  15. value = matchData[0][1];
  16. return function(object) {
  17. if (object == null) {
  18. return false;
  19. }
  20. return object[key] === value && (value !== undefined || (key in toObject(object)));
  21. };
  22. }
  23. return function(object) {
  24. return baseIsMatch(object, matchData);
  25. };
  26. }
  27. module.exports = baseMatches;