SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 2037 JavaScript
2016-01-28 01:16:24 -08:00
define(['./_baseClone', './_baseConforms'], function(baseClone, baseConforms) {
2015-12-16 17:53:20 -08:00
2016-11-13 22:49:46 -08:00
/** Used to compose bitmasks for cloning. */
var CLONE_DEEP_FLAG = 1;
2015-12-16 17:53:20 -08:00
/**
* Creates a function that invokes the predicate properties of `source` with
* the corresponding property values of a given object, returning `true` if
* all predicates return truthy, else `false`.
*
2016-07-27 17:37:08 -07:00
* **Note:** The created function is equivalent to `_.conformsTo` with
* `source` partially applied.
*
2015-12-16 17:53:20 -08:00
* @static
* @memberOf _
2016-03-26 00:00:01 -07:00
* @since 4.0.0
2015-12-16 17:53:20 -08:00
* @category Util
* @param {Object} source The object of property predicates to conform to.
2016-05-07 11:49:46 -07:00
* @returns {Function} Returns the new spec function.
2015-12-16 17:53:20 -08:00
* @example
*
2016-07-24 09:52:04 -07:00
* var objects = [
* { 'a': 2, 'b': 1 },
* { 'a': 1, 'b': 2 }
2015-12-16 17:53:20 -08:00
* ];
*
2016-07-24 09:52:04 -07:00
* _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
* // => [{ 'a': 1, 'b': 2 }]
2015-12-16 17:53:20 -08:00
*/
function conforms(source) {
2016-11-13 22:49:46 -08:00
return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
2015-12-16 17:53:20 -08:00
}
return conforms;
});