issue-126.js 1019 B

123456789101112131415161718192021222324252627282930313233
  1. // This example shows how prefiltering can be used.
  2. const diff = require('../'); // deep-diff
  3. const { log, inspect } = require('util');
  4. const assert = require('assert');
  5. const data = {
  6. issue: 126,
  7. submittedBy: 'abuzarhamza',
  8. title: 'readme.md need some additional example prefilter',
  9. posts: [
  10. {
  11. date: '2018-04-16',
  12. text: `additional example for prefilter for deep-diff would be great.
  13. https://stackoverflow.com/questions/38364639/pre-filter-condition-deep-diff-node-js`
  14. }
  15. ]
  16. };
  17. const clone = JSON.parse(JSON.stringify(data));
  18. clone.title = 'README.MD needs additional example illustrating how to prefilter';
  19. clone.disposition = 'completed';
  20. const two = diff(data, clone);
  21. const none = diff(data, clone,
  22. (path, key) => path.length === 0 && ~['title', 'disposition'].indexOf(key)
  23. );
  24. assert.equal(two.length, 2, 'should reflect two differences');
  25. assert.ok(typeof none === 'undefined', 'should reflect no differences');
  26. log(inspect(two, false, 9));
  27. log(inspect(none, false, 9));