conforms.js 978 B

123456789101112131415161718192021222324252627282930313233343536
  1. var baseClone = require('./_baseClone'),
  2. baseConforms = require('./_baseConforms');
  3. /** Used to compose bitmasks for cloning. */
  4. var CLONE_DEEP_FLAG = 1;
  5. /**
  6. * Creates a function that invokes the predicate properties of `source` with
  7. * the corresponding property values of a given object, returning `true` if
  8. * all predicates return truthy, else `false`.
  9. *
  10. * **Note:** The created function is equivalent to `_.conformsTo` with
  11. * `source` partially applied.
  12. *
  13. * @static
  14. * @memberOf _
  15. * @since 4.0.0
  16. * @category Util
  17. * @param {Object} source The object of property predicates to conform to.
  18. * @returns {Function} Returns the new spec function.
  19. * @example
  20. *
  21. * var objects = [
  22. * { 'a': 2, 'b': 1 },
  23. * { 'a': 1, 'b': 2 }
  24. * ];
  25. *
  26. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  27. * // => [{ 'a': 1, 'b': 2 }]
  28. */
  29. function conforms(source) {
  30. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  31. }
  32. module.exports = conforms;