1 var baseIsMatch = require('../internal/baseIsMatch'),
2 bindCallback = require('../internal/bindCallback'),
3 isStrictComparable = require('../internal/isStrictComparable'),
4 keys = require('../object/keys'),
5 toObject = require('../internal/toObject');
8 * Performs a deep comparison between `object` and `source` to determine if
9 * `object` contains equivalent property values. If `customizer` is provided
10 * it is invoked to compare values. If `customizer` returns `undefined`
11 * comparisons are handled by the method instead. The `customizer` is bound
12 * to `thisArg` and invoked with three arguments: (value, other, index|key).
14 * **Note:** This method supports comparing properties of arrays, booleans,
15 * `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
16 * and DOM nodes are **not** supported. Provide a customizer function to extend
17 * support for comparing other values.
22 * @param {Object} object The object to inspect.
23 * @param {Object} source The object of property values to match.
24 * @param {Function} [customizer] The function to customize value comparisons.
25 * @param {*} [thisArg] The `this` binding of `customizer`.
26 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
29 * var object = { 'user': 'fred', 'age': 40 };
31 * _.isMatch(object, { 'age': 40 });
34 * _.isMatch(object, { 'age': 36 });
37 * // using a customizer callback
38 * var object = { 'greeting': 'hello' };
39 * var source = { 'greeting': 'hi' };
41 * _.isMatch(object, source, function(value, other) {
42 * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
46 function isMatch(object, source, customizer, thisArg) {
47 var props = keys(source),
48 length = props.length;
56 customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
57 object = toObject(object);
58 if (!customizer && length == 1) {
62 if (isStrictComparable(value)) {
63 return value === object[key] && (value !== undefined || (key in object));
66 var values = Array(length),
67 strictCompareFlags = Array(length);
70 value = values[length] = source[props[length]];
71 strictCompareFlags[length] = isStrictComparable(value);
73 return baseIsMatch(object, props, values, strictCompareFlags, customizer);
76 module.exports = isMatch;