index.js 596 B

123456789101112131415161718192021222324252627
  1. /*!
  2. * is-equal-shallow <https://github.com/jonschlinkert/is-equal-shallow>
  3. *
  4. * Copyright (c) 2015, Jon Schlinkert.
  5. * Licensed under the MIT License.
  6. */
  7. 'use strict';
  8. var isPrimitive = require('is-primitive');
  9. module.exports = function isEqual(a, b) {
  10. if (!a && !b) { return true; }
  11. if (!a && b || a && !b) { return false; }
  12. var numKeysA = 0, numKeysB = 0, key;
  13. for (key in b) {
  14. numKeysB++;
  15. if (!isPrimitive(b[key]) || !a.hasOwnProperty(key) || (a[key] !== b[key])) {
  16. return false;
  17. }
  18. }
  19. for (key in a) {
  20. numKeysA++;
  21. }
  22. return numKeysA === numKeysB;
  23. };