mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Add matchesStrictComparable helper.
This commit is contained in:
33
lodash.js
33
lodash.js
@@ -3196,16 +3196,7 @@
|
||||
function baseMatches(source) {
|
||||
var matchData = getMatchData(source);
|
||||
if (matchData.length == 1 && matchData[0][2]) {
|
||||
var key = matchData[0][0],
|
||||
value = matchData[0][1];
|
||||
|
||||
return function(object) {
|
||||
if (object == null) {
|
||||
return false;
|
||||
}
|
||||
return object[key] === value &&
|
||||
(value !== undefined || (key in Object(object)));
|
||||
};
|
||||
return matchesStrictComparable(matchData[0][0], matchData[0][1]);
|
||||
}
|
||||
return function(object) {
|
||||
return object === source || baseIsMatch(object, source, matchData);
|
||||
@@ -3221,6 +3212,9 @@
|
||||
* @returns {Function} Returns the new function.
|
||||
*/
|
||||
function baseMatchesProperty(path, srcValue) {
|
||||
if (isKey(path) && isStrictComparable(srcValue)) {
|
||||
return matchesStrictComparable(path, srcValue);
|
||||
}
|
||||
return function(object) {
|
||||
var objValue = get(object, path);
|
||||
return (objValue === undefined && objValue === srcValue)
|
||||
@@ -5573,6 +5567,25 @@
|
||||
return value === value && !isObject(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* A specialized version of `matchesProperty` for source values suitable
|
||||
* for strict equality comparisons, i.e. `===`.
|
||||
*
|
||||
* @private
|
||||
* @param {string} key The key of the property to get.
|
||||
* @param {*} srcValue The value to match.
|
||||
* @returns {Function} Returns the new function.
|
||||
*/
|
||||
function matchesStrictComparable(key, srcValue) {
|
||||
return function(object) {
|
||||
if (object == null) {
|
||||
return false;
|
||||
}
|
||||
return object[key] === srcValue &&
|
||||
(srcValue !== undefined || (key in Object(object)));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the function metadata of `source` into `data`.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user