mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +00:00
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
define(['./baseIsMatch', '../utility/constant', './isStrictComparable', '../object/keys', './toObject'], function(baseIsMatch, constant, isStrictComparable, keys, toObject) {
|
|
|
|
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
|
|
var undefined;
|
|
|
|
/**
|
|
* The base implementation of `_.matches` which does not clone `source`.
|
|
*
|
|
* @private
|
|
* @param {Object} source The object of property values to match.
|
|
* @returns {Function} Returns the new function.
|
|
*/
|
|
function baseMatches(source) {
|
|
var props = keys(source),
|
|
length = props.length;
|
|
|
|
if (!length) {
|
|
return constant(true);
|
|
}
|
|
if (length == 1) {
|
|
var key = props[0],
|
|
value = source[key];
|
|
|
|
if (isStrictComparable(value)) {
|
|
return function(object) {
|
|
if (object == null) {
|
|
return false;
|
|
}
|
|
return object[key] === value && (value !== undefined || (key in toObject(object)));
|
|
};
|
|
}
|
|
}
|
|
var values = Array(length),
|
|
strictCompareFlags = Array(length);
|
|
|
|
while (length--) {
|
|
value = source[props[length]];
|
|
values[length] = value;
|
|
strictCompareFlags[length] = isStrictComparable(value);
|
|
}
|
|
return function(object) {
|
|
return object != null && baseIsMatch(toObject(object), props, values, strictCompareFlags);
|
|
};
|
|
}
|
|
|
|
return baseMatches;
|
|
});
|