Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- const diff = require('deep-object-diff') ; // thank you matt phillip.
- const util = require('util') ;
- diffMe ( ':nothing::'
- , [ {ONE_1: 'one one', ONE_2: 'one two' } , {TWO_1: 'two one', TWO_2: 'two two'} ]
- , [ {ONE_1: 'one one', ONE_2: 'one two'} , {TWO_1: 'two one', TWO_2: 'two two'} ]
- );
- diffMe ( ':edited::'
- , [ {ONE_1: 'one one', ONE_2: 'one two' } , {TWO_1: 'two one', TWO_2: 'two two'} ]
- , [ {ONE_1: 'one one', ONE_2: 'one two'} , {TWO_1: 'two one', TWO_2: 'two two edited!'} ]
- );
- diffMe ( ':deleted::'
- , [ {ONE_1: 'one one', ONE_2: 'one two' } , {TWO_1: 'two one', TWO_2: 'two two'} ]
- , [ {ONE_1: 'one one', ONE_2: 'one two'} , {TWO_1: 'two one' } ]
- );
- diffMe ( ':deleted!!::'
- , [ {ONE_1: 'one one', ONE_2: 'one two' } , {TWO_1: 'two one', TWO_2: 'two two'} ]
- , [ {ONE_1: 'one one', ONE_2: 'one two'} ]
- );
- diffMe ( ':added::'
- , [ {ONE_1: 'one one', ONE_2: 'one two' } , {TWO_1: 'two one', TWO_2: 'two two'} ]
- , [ {ONE_1: 'one one', ONE_2: 'one two'} , {TWO_1: 'two one', TWO_2: 'two two!', TWO_3:'two three added!'} ]
- );
- function diffMe(title, lhs, rhs) {
- console.log("\n" + title);
- displayObject(0, title, diff(lhs, rhs) ) ;
- }
- function displayObject(level, title, object) {
- if ( typeof object === 'object' ) {
- for ( var key in object ) {
- displayObject(level + 1, key, object[key] );
- }
- } else {
- console.log(' '.repeat(level * 4) + 'level: ' + level + ' title: ' + title + ' value: ' + object );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement