Skip to content
Permalink
Newer
Older
100644 39 lines (36 sloc) 1.12 KB
1
var baseClone = require('./_baseClone'),
2
baseMatches = require('./_baseMatches');
3
4
/** Used to compose bitmasks for cloning. */
5
var CLONE_DEEP_FLAG = 1;
6
7
/**
8
* Creates a function that performs a partial deep comparison between a given
9
* object and `source`, returning `true` if the given object has equivalent
10
* property values, else `false`.
11
*
12
* **Note:** The created function is equivalent to `_.isMatch` with `source`
13
* partially applied.
14
*
15
* Partial comparisons will match empty array and empty object `source`
16
* values against any array or object value, respectively. See `_.isEqual`
17
* for a list of supported value comparisons.
18
*
19
* @static
20
* @memberOf _
21
* @since 3.0.0
22
* @category Util
23
* @param {Object} source The object of property values to match.
24
* @returns {Function} Returns the new spec function.
25
* @example
26
*
27
* var objects = [
28
* { 'a': 1, 'b': 2, 'c': 3 },
29
* { 'a': 4, 'b': 5, 'c': 6 }
30
* ];
31
*
32
* _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
33
* // => [{ 'a': 4, 'b': 5, 'c': 6 }]
34
*/
35
function matches(source) {
36
return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
37
}
38
39
module.exports = matches;