mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Adjust object checks in baseIsMatch, baseMatches, baseMatchesProperty, & isMatch.
This commit is contained in:
@@ -2383,11 +2383,8 @@
|
|||||||
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
||||||
*/
|
*/
|
||||||
function baseIsMatch(object, props, values, strictCompareFlags, customizer) {
|
function baseIsMatch(object, props, values, strictCompareFlags, customizer) {
|
||||||
var length = props.length;
|
|
||||||
if (object == null) {
|
|
||||||
return !length;
|
|
||||||
}
|
|
||||||
var index = -1,
|
var index = -1,
|
||||||
|
length = props.length,
|
||||||
noCustomizer = !customizer;
|
noCustomizer = !customizer;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
@@ -2400,13 +2397,13 @@
|
|||||||
}
|
}
|
||||||
index = -1;
|
index = -1;
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var key = props[index];
|
var key = props[index],
|
||||||
if (noCustomizer && strictCompareFlags[index]) {
|
objValue = object[key],
|
||||||
var result = key in object;
|
srcValue = values[index];
|
||||||
} else {
|
|
||||||
var objValue = object[key],
|
|
||||||
srcValue = values[index];
|
|
||||||
|
|
||||||
|
if (noCustomizer && strictCompareFlags[index]) {
|
||||||
|
var result = typeof objValue != 'undefined' || (key in object);
|
||||||
|
} else {
|
||||||
result = customizer ? customizer(objValue, srcValue, key) : undefined;
|
result = customizer ? customizer(objValue, srcValue, key) : undefined;
|
||||||
if (typeof result == 'undefined') {
|
if (typeof result == 'undefined') {
|
||||||
result = baseIsEqual(srcValue, objValue, customizer, true);
|
result = baseIsEqual(srcValue, objValue, customizer, true);
|
||||||
@@ -2447,13 +2444,17 @@
|
|||||||
var props = keys(source),
|
var props = keys(source),
|
||||||
length = props.length;
|
length = props.length;
|
||||||
|
|
||||||
|
if (!length) {
|
||||||
|
return constant(true);
|
||||||
|
}
|
||||||
if (length == 1) {
|
if (length == 1) {
|
||||||
var key = props[0],
|
var key = props[0],
|
||||||
value = source[key];
|
value = source[key];
|
||||||
|
|
||||||
if (isStrictComparable(value)) {
|
if (isStrictComparable(value)) {
|
||||||
return function(object) {
|
return function(object) {
|
||||||
return object != null && object[key] === value && key in object;
|
return object != null && object[key] === value &&
|
||||||
|
(typeof value != 'undefined' || (key in toObject(object)));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2466,7 +2467,7 @@
|
|||||||
strictCompareFlags[length] = isStrictComparable(value);
|
strictCompareFlags[length] = isStrictComparable(value);
|
||||||
}
|
}
|
||||||
return function(object) {
|
return function(object) {
|
||||||
return baseIsMatch(object, props, values, strictCompareFlags);
|
return object != null && baseIsMatch(toObject(object), props, values, strictCompareFlags);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2482,7 +2483,8 @@
|
|||||||
function baseMatchesProperty(key, value) {
|
function baseMatchesProperty(key, value) {
|
||||||
if (isStrictComparable(value)) {
|
if (isStrictComparable(value)) {
|
||||||
return function(object) {
|
return function(object) {
|
||||||
return object != null && object[key] === value && key in object;
|
return object != null && object[key] === value &&
|
||||||
|
(typeof value != 'undefined' || (key in toObject(object)));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return function(object) {
|
return function(object) {
|
||||||
@@ -8715,13 +8717,19 @@
|
|||||||
var props = keys(source),
|
var props = keys(source),
|
||||||
length = props.length;
|
length = props.length;
|
||||||
|
|
||||||
|
if (!length) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (object == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
|
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
|
||||||
if (!customizer && length == 1) {
|
if (!customizer && length == 1) {
|
||||||
var key = props[0],
|
var key = props[0],
|
||||||
value = source[key];
|
value = source[key];
|
||||||
|
|
||||||
if (isStrictComparable(value)) {
|
if (isStrictComparable(value)) {
|
||||||
return object != null && value === object[key] && key in object;
|
return value === object[key] && (typeof value != 'undefined' || (key in toObject(object)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var values = Array(length),
|
var values = Array(length),
|
||||||
@@ -8731,7 +8739,7 @@
|
|||||||
value = values[length] = source[props[length]];
|
value = values[length] = source[props[length]];
|
||||||
strictCompareFlags[length] = isStrictComparable(value);
|
strictCompareFlags[length] = isStrictComparable(value);
|
||||||
}
|
}
|
||||||
return baseIsMatch(object, props, values, strictCompareFlags, customizer);
|
return baseIsMatch(toObject(object), props, values, strictCompareFlags, customizer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user