1
|
(function (global, factory) {
|
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
3
|
typeof define === 'function' && define.amd ? define(factory) :
|
4
|
(global.valueEqual = factory());
|
5
|
}(this, (function () { 'use strict';
|
6
|
|
7
|
function valueOf(obj) {
|
8
|
return obj.valueOf ? obj.valueOf() : Object.prototype.valueOf.call(obj);
|
9
|
}
|
10
|
|
11
|
function valueEqual(a, b) {
|
12
|
// Test for strict equality first.
|
13
|
if (a === b) return true;
|
14
|
|
15
|
// Otherwise, if either of them == null they are not equal.
|
16
|
if (a == null || b == null) return false;
|
17
|
|
18
|
if (Array.isArray(a)) {
|
19
|
return (
|
20
|
Array.isArray(b) &&
|
21
|
a.length === b.length &&
|
22
|
a.every(function(item, index) {
|
23
|
return valueEqual(item, b[index]);
|
24
|
})
|
25
|
);
|
26
|
}
|
27
|
|
28
|
if (typeof a === 'object' || typeof b === 'object') {
|
29
|
var aValue = valueOf(a);
|
30
|
var bValue = valueOf(b);
|
31
|
|
32
|
if (aValue !== a || bValue !== b) return valueEqual(aValue, bValue);
|
33
|
|
34
|
return Object.keys(Object.assign({}, a, b)).every(function(key) {
|
35
|
return valueEqual(a[key], b[key]);
|
36
|
});
|
37
|
}
|
38
|
|
39
|
return false;
|
40
|
}
|
41
|
|
42
|
return valueEqual;
|
43
|
|
44
|
})));
|