UNPKG

873 BJavaScriptView Raw
1var hasOwn = require('./hasOwn');
2var every = require('./every');
3var isObject = require('../lang/isObject');
4var is = require('../lang/is');
5
6 // Makes a function to compare the object values from the specified compare
7 // operation callback.
8 function makeCompare(callback) {
9 return function(value, key) {
10 return hasOwn(this, key) && callback(value, this[key]);
11 };
12 }
13
14 function checkProperties(value, key) {
15 return hasOwn(this, key);
16 }
17
18 /**
19 * Checks if two objects have the same keys and values.
20 */
21 function equals(a, b, callback) {
22 callback = callback || is;
23
24 if (!isObject(a) || !isObject(b)) {
25 return callback(a, b);
26 }
27
28 return (every(a, makeCompare(callback), b) &&
29 every(b, checkProperties, a));
30 }
31
32 module.exports = equals;
33