mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
import baseIsEqual from './baseIsEqual';
|
|
|
|
/**
|
|
* The base implementation of `_.isMatch` without support for callback
|
|
* shorthands and `this` binding.
|
|
*
|
|
* @private
|
|
* @param {Object} object The object to inspect.
|
|
* @param {Array} props The source property names to match.
|
|
* @param {Array} values The source values to match.
|
|
* @param {Array} strictCompareFlags Strict comparison flags for source values.
|
|
* @param {Function} [customizer] The function to customize comparing objects.
|
|
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
|
*/
|
|
function baseIsMatch(object, props, values, strictCompareFlags, customizer) {
|
|
var index = -1,
|
|
length = props.length,
|
|
noCustomizer = !customizer;
|
|
|
|
while (++index < length) {
|
|
if ((noCustomizer && strictCompareFlags[index])
|
|
? values[index] !== object[props[index]]
|
|
: !(props[index] in object)
|
|
) {
|
|
return false;
|
|
}
|
|
}
|
|
index = -1;
|
|
while (++index < length) {
|
|
var key = props[index],
|
|
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;
|
|
if (typeof result == 'undefined') {
|
|
result = baseIsEqual(srcValue, objValue, customizer, true);
|
|
}
|
|
}
|
|
if (!result) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
export default baseIsMatch;
|