1.0.4 • Published 5 years ago

deep-object-changes v1.0.4

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

deep-object-changes

npm size issues stars

Compares two objects, an original and an updated version and returns an object with only the changes.

Will deep compare objects recursively, but will only shallow compare arrays.

This module is useful for working out the bare minimum payload needed to send to a server.

Example

  import deepObjectChanges from 'deep-object-changes';
  
  const EXAMPLE_USER_RES = {
    firstName: 'Emperor',
    lastName: 'Palpatine',
    age: 75,
    location: {
      street: 'Death Star',
      postCode: 'SPACE'
    }
  };
  
  const EXAMPLE_CHANGED_USER = {
    firstName: 'Emperor',
    lastName: 'Palpatine',
    age: 85,
     location: {
      street: 'Death Star',
      postCode: 'GALAXY'
    }
  }
  
  deepObjectChanges(EXAMPLE_USER_RES, EXAMPLE_CHANGED_USER);
  
  /**
    Outputs: 
    
    {
      age: 85,
       location: {
        postCode: 'GALAXY'
      }
    }
 */
  
1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago