2016-10-10 03:43:44 +02:00
|
|
|
var baseClone = require('./_baseClone'),
|
|
|
|
baseMatchesProperty = require('./_baseMatchesProperty');
|
|
|
|
|
2016-11-16 01:59:39 +01:00
|
|
|
/** Used to compose bitmasks for cloning. */
|
|
|
|
var CLONE_DEEP_FLAG = 1;
|
|
|
|
|
2016-10-10 03:43:44 +02:00
|
|
|
/**
|
|
|
|
* Creates a function that performs a partial deep comparison between the
|
|
|
|
* value at `path` of a given object to `srcValue`, returning `true` if the
|
|
|
|
* object value is equivalent, else `false`.
|
|
|
|
*
|
|
|
|
* **Note:** Partial comparisons will match empty array and empty object
|
|
|
|
* `srcValue` values against any array or object value, respectively. See
|
|
|
|
* `_.isEqual` for a list of supported value comparisons.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @memberOf _
|
|
|
|
* @since 3.2.0
|
|
|
|
* @category Util
|
|
|
|
* @param {Array|string} path The path of the property to get.
|
|
|
|
* @param {*} srcValue The value to match.
|
|
|
|
* @returns {Function} Returns the new spec function.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* var objects = [
|
|
|
|
* { 'a': 1, 'b': 2, 'c': 3 },
|
|
|
|
* { 'a': 4, 'b': 5, 'c': 6 }
|
|
|
|
* ];
|
|
|
|
*
|
|
|
|
* _.find(objects, _.matchesProperty('a', 4));
|
|
|
|
* // => { 'a': 4, 'b': 5, 'c': 6 }
|
|
|
|
*/
|
|
|
|
function matchesProperty(path, srcValue) {
|
2016-11-16 01:59:39 +01:00
|
|
|
return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
|
2016-10-10 03:43:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = matchesProperty;
|