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 | * **Note:** Multiple values can be checked by combining several matchers
|
---|
20 | * using `_.overSome`
|
---|
21 | *
|
---|
22 | * @static
|
---|
23 | * @memberOf _
|
---|
24 | * @since 3.0.0
|
---|
25 | * @category Util
|
---|
26 | * @param {Object} source The object of property values to match.
|
---|
27 | * @returns {Function} Returns the new spec function.
|
---|
28 | * @example
|
---|
29 | *
|
---|
30 | * var objects = [
|
---|
31 | * { 'a': 1, 'b': 2, 'c': 3 },
|
---|
32 | * { 'a': 4, 'b': 5, 'c': 6 }
|
---|
33 | * ];
|
---|
34 | *
|
---|
35 | * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
|
---|
36 | * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
|
---|
37 | *
|
---|
38 | * // Checking for several possible values
|
---|
39 | * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
|
---|
40 | * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
|
---|
41 | */
|
---|
42 | function matches(source) {
|
---|
43 | return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
|
---|
44 | }
|
---|
45 |
|
---|
46 | module.exports = matches;
|
---|