SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 9 JavaScript
2016-01-28 01:16:24 -08:00
define(['./_Stack', './_baseIsEqual'], function(Stack, baseIsEqual) {
2015-01-08 00:37:01 -08:00
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
2016-11-13 22:49:46 -08:00
/** Used to compose bitmasks for value comparisons. */
var COMPARE_PARTIAL_FLAG = 1,
COMPARE_UNORDERED_FLAG = 2;
2015-12-16 17:53:20 -08:00
2015-01-08 00:37:01 -08:00
/**
2015-12-16 17:53:20 -08:00
* The base implementation of `_.isMatch` without support for iteratee shorthands.
2015-01-08 00:37:01 -08:00
*
* @private
2015-12-16 17:46:22 -08:00
* @param {Object} object The object to inspect.
2015-12-16 17:53:20 -08:00
* @param {Object} source The object of property values to match.
* @param {Array} matchData The property names, values, and compare flags to match.
* @param {Function} [customizer] The function to customize comparisons.
2015-01-08 00:37:01 -08:00
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
*/
2015-12-16 17:53:20 -08:00
function baseIsMatch(object, source, matchData, customizer) {
2015-12-16 17:50:42 -08:00
var index = matchData.length,
length = index,
2015-01-08 00:37:01 -08:00
noCustomizer = !customizer;
2015-12-16 17:50:42 -08:00
if (object == null) {
return !length;
}
2015-12-16 17:53:20 -08:00
object = Object(object);
2015-12-16 17:50:42 -08:00
while (index--) {
var data = matchData[index];
if ((noCustomizer && data[2])
? data[1] !== object[data[0]]
: !(data[0] in object)
2015-01-08 00:37:01 -08:00
) {
return false;
}
}
while (++index < length) {
2015-12-16 17:50:42 -08:00
data = matchData[index];
var key = data[0],
2015-12-16 17:49:07 -08:00
objValue = object[key],
2015-12-16 17:50:42 -08:00
srcValue = data[1];
2015-12-16 17:49:07 -08:00
2015-12-16 17:50:42 -08:00
if (noCustomizer && data[2]) {
if (objValue === undefined && !(key in object)) {
return false;
}
2015-01-08 00:37:01 -08:00
} else {
2016-03-26 00:00:01 -07:00
var stack = new Stack;
if (customizer) {
var result = customizer(objValue, srcValue, key, object, source, stack);
}
2016-01-24 18:06:10 -08:00
if (!(result === undefined
2016-11-13 22:49:46 -08:00
? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
2016-01-24 18:06:10 -08:00
: result
)) {
2015-12-16 17:50:42 -08:00
return false;
2015-01-08 00:37:01 -08:00
}
}
}
return true;
}
return baseIsMatch;
});