Skip to content

Evaw/objectDiff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

objectDiff Build Status

Usage

objectDiff will get the extra and different properties of the first object

ex.

objectDiff(
  {
    steel: {
      sword: {
        weight: 20
      }
    }
  },
  {
    steel: {
      train: {
        contains: "coal"
      }
    }
  });

yields

  {
    steel: {
      sword: {
        weight: 20
      }
    }
  }

because all the stuff in a is not in b (this diff shows extra or different, only for the first object). You can get the same for the second object by reversing the order in your call

if two objects are are the same, objectDiff yields undefined

ex.

  objectDiff({}, {}) === undefined //true

more examples.

  objectDiff(
  {
    steel: {
      sword:{
        weight: 10
      },
      train: {
        hasCoal: true
      }
    }
  },
  {
    steel: {
      sword: {
        weight: 10
      }
    }
  });

yields

{
  steel: {
    train: {
      hasCoal: true
    }
  }
}

because the first object is only different in the path steel.train.hasCoal

Warning

make sure you run tests with data that resembles your application

There are things that may not be implemented. Circular structures come to mind as they have not been tested.

Developing

get the dependencies

yarn

lint

yarn run lint

test

yarn run test
yarn run test -- --watch

About

Object difference js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published