Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. 'use strict'
  2. const diff = require('deep-object-diff') ; // thank you matt phillip.
  3. const util = require('util') ;
  4.  
  5. diffMe ( ':nothing::'
  6. , [ {ONE_1: 'one one', ONE_2: 'one two' } , {TWO_1: 'two one', TWO_2: 'two two'} ]
  7. , [ {ONE_1: 'one one', ONE_2: 'one two'} , {TWO_1: 'two one', TWO_2: 'two two'} ]
  8. );
  9.  
  10. diffMe ( ':edited::'
  11. , [ {ONE_1: 'one one', ONE_2: 'one two' } , {TWO_1: 'two one', TWO_2: 'two two'} ]
  12. , [ {ONE_1: 'one one', ONE_2: 'one two'} , {TWO_1: 'two one', TWO_2: 'two two edited!'} ]
  13. );
  14.  
  15. diffMe ( ':deleted::'
  16. , [ {ONE_1: 'one one', ONE_2: 'one two' } , {TWO_1: 'two one', TWO_2: 'two two'} ]
  17. , [ {ONE_1: 'one one', ONE_2: 'one two'} , {TWO_1: 'two one' } ]
  18. );
  19.  
  20. diffMe ( ':deleted!!::'
  21. , [ {ONE_1: 'one one', ONE_2: 'one two' } , {TWO_1: 'two one', TWO_2: 'two two'} ]
  22. , [ {ONE_1: 'one one', ONE_2: 'one two'} ]
  23. );
  24.  
  25. diffMe ( ':added::'
  26. , [ {ONE_1: 'one one', ONE_2: 'one two' } , {TWO_1: 'two one', TWO_2: 'two two'} ]
  27. , [ {ONE_1: 'one one', ONE_2: 'one two'} , {TWO_1: 'two one', TWO_2: 'two two!', TWO_3:'two three added!'} ]
  28. );
  29.  
  30.  
  31. function diffMe(title, lhs, rhs) {
  32. console.log("\n" + title);
  33. displayObject(0, title, diff(lhs, rhs) ) ;
  34. }
  35.  
  36. function displayObject(level, title, object) {
  37. if ( typeof object === 'object' ) {
  38. for ( var key in object ) {
  39. displayObject(level + 1, key, object[key] );
  40. }
  41. } else {
  42. console.log(' '.repeat(level * 4) + 'level: ' + level + ' title: ' + title + ' value: ' + object );
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement