UNPKG

911 BJavaScriptView Raw
1import baseClone from './_baseClone';
2import baseMatchesProperty from './_baseMatchesProperty';
3
4/**
5 * Creates a function that performs a partial deep comparison between the
6 * value at `path` of a given object to `srcValue`, returning `true` if the
7 * object value is equivalent, else `false`.
8 *
9 * **Note:** This method supports comparing the same values as `_.isEqual`.
10 *
11 * @static
12 * @memberOf _
13 * @since 3.2.0
14 * @category Util
15 * @param {Array|string} path The path of the property to get.
16 * @param {*} srcValue The value to match.
17 * @returns {Function} Returns the new function.
18 * @example
19 *
20 * var users = [
21 * { 'user': 'barney' },
22 * { 'user': 'fred' }
23 * ];
24 *
25 * _.find(users, _.matchesProperty('user', 'fred'));
26 * // => { 'user': 'fred' }
27 */
28function matchesProperty(path, srcValue) {
29 return baseMatchesProperty(path, baseClone(srcValue, true));
30}
31
32export default matchesProperty;