_baseConforms.js 757 B

123456789101112131415161718192021222324252627282930313233
  1. var keys = require('./keys');
  2. /**
  3. * The base implementation of `_.conforms` which doesn't clone `source`.
  4. *
  5. * @private
  6. * @param {Object} source The object of property predicates to conform to.
  7. * @returns {Function} Returns the new spec function.
  8. */
  9. function baseConforms(source) {
  10. var props = keys(source),
  11. length = props.length;
  12. return function(object) {
  13. if (object == null) {
  14. return !length;
  15. }
  16. var index = length;
  17. while (index--) {
  18. var key = props[index],
  19. predicate = source[key],
  20. value = object[key];
  21. if ((value === undefined &&
  22. !(key in Object(object))) || !predicate(value)) {
  23. return false;
  24. }
  25. }
  26. return true;
  27. };
  28. }
  29. module.exports = baseConforms;