diffOps.js 540 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var keys = require('object-keys');
  3. var forEach = require('foreach');
  4. module.exports = function diffOperations(actual, expected, expectedMissing) {
  5. var actualKeys = keys(actual);
  6. var expectedKeys = keys(expected);
  7. var extra = [];
  8. var missing = [];
  9. forEach(actualKeys, function (op) {
  10. if (!(op in expected)) {
  11. extra.push(op);
  12. }
  13. });
  14. forEach(expectedKeys, function (op) {
  15. if (!(op in actual) && expectedMissing.indexOf(op) === -1) {
  16. missing.push(op);
  17. }
  18. });
  19. return { missing: missing, extra: extra };
  20. };