mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
33 lines
943 B
JavaScript
33 lines
943 B
JavaScript
import baseClone from '../internal/baseClone';
|
|
import baseMatchesProperty from '../internal/baseMatchesProperty';
|
|
|
|
/**
|
|
* Creates a function which compares the property value of `path` on a given
|
|
* object to `value`.
|
|
*
|
|
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
|
|
* numbers, `Object` objects, regexes, and strings. Objects are compared by
|
|
* their own, not inherited, enumerable properties.
|
|
*
|
|
* @static
|
|
* @memberOf _
|
|
* @category Utility
|
|
* @param {Array|string} path The path of the property to get.
|
|
* @param {*} value The value to compare.
|
|
* @returns {Function} Returns the new function.
|
|
* @example
|
|
*
|
|
* var users = [
|
|
* { 'user': 'barney' },
|
|
* { 'user': 'fred' }
|
|
* ];
|
|
*
|
|
* _.find(users, _.matchesProperty('user', 'fred'));
|
|
* // => { 'user': 'fred' }
|
|
*/
|
|
function matchesProperty(path, value) {
|
|
return baseMatchesProperty(path, baseClone(value, true));
|
|
}
|
|
|
|
export default matchesProperty;
|