forked from lodash/lodash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conforms.js
33 lines (30 loc) · 958 Bytes
/
conforms.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import baseClone from './.internal/baseClone.js'
import baseConforms from './.internal/baseConforms.js'
/** Used to compose bitmasks for cloning. */
const CLONE_DEEP_FLAG = 1
/**
* 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`.
*
* **Note:** The created function is equivalent to `conformsTo` with
* `source` partially applied.
*
* @since 4.0.0
* @category Util
* @param {Object} source The object of property predicates to conform to.
* @returns {Function} Returns the new spec function.
* @example
*
* const objects = [
* { 'a': 2, 'b': 1 },
* { 'a': 1, 'b': 2 }
* ]
*
* filter(objects, conforms({ 'b': function(n) { return n > 1 } }))
* // => [{ 'a': 1, 'b': 2 }]
*/
function conforms(source) {
return baseConforms(baseClone(source, CLONE_DEEP_FLAG))
}
export default conforms