index.js 802 B

12345678910111213141516171819202122232425262728293031
  1. var has = Object.prototype.hasOwnProperty;
  2. function dequal(foo, bar) {
  3. var ctor, len;
  4. if (foo === bar) return true;
  5. if (foo && bar && (ctor=foo.constructor) === bar.constructor) {
  6. if (ctor === Date) return foo.getTime() === bar.getTime();
  7. if (ctor === RegExp) return foo.toString() === bar.toString();
  8. if (ctor === Array) {
  9. if ((len=foo.length) === bar.length) {
  10. while (len-- && dequal(foo[len], bar[len]));
  11. }
  12. return len === -1;
  13. }
  14. if (!ctor || typeof foo === 'object') {
  15. len = 0;
  16. for (ctor in foo) {
  17. if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
  18. if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
  19. }
  20. return Object.keys(bar).length === len;
  21. }
  22. }
  23. return foo !== foo && bar !== bar;
  24. }
  25. exports.dequal = dequal;