9bc7ac1744227df5f4be74e4595a5812963254d2
[platform/framework/web/crosswalk-tizen.git] /
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');
6
7 /**
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).
13  *
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.
18  *
19  * @static
20  * @memberOf _
21  * @category Lang
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`.
27  * @example
28  *
29  * var object = { 'user': 'fred', 'age': 40 };
30  *
31  * _.isMatch(object, { 'age': 40 });
32  * // => true
33  *
34  * _.isMatch(object, { 'age': 36 });
35  * // => false
36  *
37  * // using a customizer callback
38  * var object = { 'greeting': 'hello' };
39  * var source = { 'greeting': 'hi' };
40  *
41  * _.isMatch(object, source, function(value, other) {
42  *   return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
43  * });
44  * // => true
45  */
46 function isMatch(object, source, customizer, thisArg) {
47   var props = keys(source),
48       length = props.length;
49
50   if (!length) {
51     return true;
52   }
53   if (object == null) {
54     return false;
55   }
56   customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
57   object = toObject(object);
58   if (!customizer && length == 1) {
59     var key = props[0],
60         value = source[key];
61
62     if (isStrictComparable(value)) {
63       return value === object[key] && (value !== undefined || (key in object));
64     }
65   }
66   var values = Array(length),
67       strictCompareFlags = Array(length);
68
69   while (length--) {
70     value = values[length] = source[props[length]];
71     strictCompareFlags[length] = isStrictComparable(value);
72   }
73   return baseIsMatch(object, props, values, strictCompareFlags, customizer);
74 }
75
76 module.exports = isMatch;