_baseConformsTo.js 718 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * The base implementation of `_.conformsTo` which accepts `props` to check.
  3. *
  4. * @private
  5. * @param {Object} object The object to inspect.
  6. * @param {Object} source The object of property predicates to conform to.
  7. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  8. */
  9. function baseConformsTo(object, source, props) {
  10. var length = props.length;
  11. if (object == null) {
  12. return !length;
  13. }
  14. object = Object(object);
  15. while (length--) {
  16. var key = props[length],
  17. predicate = source[key],
  18. value = object[key];
  19. if ((value === undefined && !(key in object)) || !predicate(value)) {
  20. return false;
  21. }
  22. }
  23. return true;
  24. }
  25. module.exports = baseConformsTo;