compareobj

Compare objects or json strings.

npm install compareobj
4 downloads in the last week
17 downloads in the last month

compareobj

(c)Bumblehead, 2013 MIT-license

OVERVIEW:

compareobj is a script for comparing javascript objects. To my knowledge, it is most useful for writing unit tests and for comparing static json files that would used for web applications.


INSTALL:

compareobj may be downloaded directly or installed through npm.

  • npm

    $ npm install compareobj
    
  • Direct Download

    $ git clone https://github.com/iambumblehead/compareobj.git
    

TEST:

to run tests, use npm test from a shell.

 $ npm test

<a id=usage">USAGE:

compare two objects to see if they have definition for the same members

   var CompareObj = require('../compareobj');
   CompareObj.isSameMembersDefinedObj({
      prop1 : true,
      prop2 : {
        prop2a : {
          prop2a1 : true
        }
      }   
   }, {
      prop1 : true,
      prop2 : {
        prop2a : {}
      }   
   }); // false
   var CompareObj = require('../compareobj');
   CompareObj.isSameMembersDefinedObj({
      prop1 : true,
      prop2 : {
        prop2a : {
          prop2a1 : true
        }
      }   
   }, {
      prop1 : true,
      prop2 : {
        prop2a : {
          prop2a1 : true
        }
      }   
   }); // true

isSameMembers will also accept a callback

   var CompareObj = require('../compareobj');
   CompareObj.isSameMembersDefinedSameObj({
      prop1 : true,
      prop2 : {
        prop2a : {
          prop2a1 : true,
          prop2a2 : true
        }
      }   
   }, {
      prop1 : true,
      prop2 : {
        prop2a : {}
      }   
   }, function (type, propertyName) {
     console.log(type, propertyName);
   });
   // child prop2
   // property prop2a2

compare two objects to see if they have the same definition for the given members of the first object.

   var CompareObj = require('../compareobj');
   CompareObj.isSameMembersDefinedObj({
      prop1 : true,
      prop2 : {
        prop2a : {
          prop2a1 : true
        }
      }   
   }, {
      prop1 : true,
      prop2 : {
        prop2a : {
          prop2a1 : true
        }
      }   
   }); // true
   var CompareObj = require('../compareobj');
   CompareObj.isSameMembersDefinedObj({
      prop1 : true,
      prop2 : {
        prop2a : {
          prop2a1 : true
        }
      }   
   }, {
      prop1 : true,
      prop2 : {
        prop2a : {
          prop2a1 : false
        }
      }   
   }); // false

License:

(The MIT License)

Copyright (c) 2013 Bumblehead chris@bumblehead.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

npm loves you