Files
kami-parse-server/src/LiveQuery/equalObjects.js

49 lines
1000 B
JavaScript
Raw Normal View History

2016-03-10 14:27:00 -08:00
var toString = Object.prototype.toString;
/**
* Determines whether two objects represent the same primitive, special Parse
* type, or full Parse Object.
*/
function equalObjects(a, b) {
if (typeof a !== typeof b) {
return false;
}
if (typeof a !== 'object') {
return (a === b);
}
if (a === b) {
return true;
}
if (toString.call(a) === '[object Date]') {
if (toString.call(b) === '[object Date]') {
return (+a === +b);
}
return false;
}
if (Array.isArray(a)) {
if (Array.isArray(b)) {
if (a.length !== b.length) {
return false;
}
for (var i = 0; i < a.length; i++) {
if (!equalObjects(a[i], b[i])) {
return false;
}
}
return true;
}
return false;
}
if (Object.keys(a).length !== Object.keys(b).length) {
return false;
}
for (var key in a) {
if (!equalObjects(a[key], b[key])) {
return false;
}
}
return true;
}
module.exports = equalObjects;