equalObjects.js 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. var toString = Object.prototype.toString;
  3. /**
  4. * Determines whether two objects represent the same primitive, special Parse
  5. * type, or full Parse Object.
  6. */
  7. function equalObjects(a, b) {
  8. if (typeof a !== typeof b) {
  9. return false;
  10. }
  11. if (typeof a !== 'object') {
  12. return a === b;
  13. }
  14. if (a === b) {
  15. return true;
  16. }
  17. if (toString.call(a) === '[object Date]') {
  18. if (toString.call(b) === '[object Date]') {
  19. return +a === +b;
  20. }
  21. return false;
  22. }
  23. if (Array.isArray(a)) {
  24. if (Array.isArray(b)) {
  25. if (a.length !== b.length) {
  26. return false;
  27. }
  28. for (var i = 0; i < a.length; i++) {
  29. if (!equalObjects(a[i], b[i])) {
  30. return false;
  31. }
  32. }
  33. return true;
  34. }
  35. return false;
  36. }
  37. if (Object.keys(a).length !== Object.keys(b).length) {
  38. return false;
  39. }
  40. for (var key in a) {
  41. if (!equalObjects(a[key], b[key])) {
  42. return false;
  43. }
  44. }
  45. return true;
  46. }
  47. module.exports = equalObjects;
  48. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJ0b1N0cmluZyIsIk9iamVjdCIsInByb3RvdHlwZSIsImVxdWFsT2JqZWN0cyIsImEiLCJiIiwiY2FsbCIsIkFycmF5IiwiaXNBcnJheSIsImxlbmd0aCIsImkiLCJrZXlzIiwia2V5IiwibW9kdWxlIiwiZXhwb3J0cyJdLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9MaXZlUXVlcnkvZXF1YWxPYmplY3RzLmpzIl0sInNvdXJjZXNDb250ZW50IjpbInZhciB0b1N0cmluZyA9IE9iamVjdC5wcm90b3R5cGUudG9TdHJpbmc7XG5cbi8qKlxuICogRGV0ZXJtaW5lcyB3aGV0aGVyIHR3byBvYmplY3RzIHJlcHJlc2VudCB0aGUgc2FtZSBwcmltaXRpdmUsIHNwZWNpYWwgUG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