conformsTo.js 954 B

123456789101112131415161718192021222324252627282930313233
  1. var baseConformsTo = require('./_baseConformsTo'),
  2. keys = require('./keys');
  3. /**
  4. * Checks if `object` conforms to `source` by invoking the predicate
  5. * properties of `source` with the corresponding property values of `object`.
  6. *
  7. * **Note:** This method is equivalent to `_.conforms` when `source` is
  8. * partially applied.
  9. *
  10. * @static
  11. * @memberOf _
  12. * @since 4.14.0
  13. * @category Lang
  14. * @param {Object} object The object to inspect.
  15. * @param {Object} source The object of property predicates to conform to.
  16. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  17. * @example
  18. *
  19. * var object = { 'a': 1, 'b': 2 };
  20. *
  21. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  22. * // => true
  23. *
  24. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  25. * // => false
  26. */
  27. function conformsTo(object, source) {
  28. return source == null || baseConformsTo(object, source, keys(source));
  29. }
  30. module.exports = conformsTo;