0.1.0 • Published 5 years ago

object-key-compare v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

object-key-compare

Javascript object key comparison library

compare(compareObject, toObject)

Lists all second parameter's keys that do not have a counterpart in the first parameter (Converse nonimplication logical operation)

Parameters

  1. compareObject: object that is being tested
  2. toObject: object that is tested against

Return value

A object

{
  missingKeys:[] // list of keys that toObject has but compareObject doesn't
  subObjects: { // matching keys with objects as values are compared recursively
    [matchingKey]: {
      missingKeys: ...
      subObjects: ...
    }
  }
}

Example

const { compare } = require('object-key-compare');

const objectA = {
  no: 'yes',
  foo: 'bar',
  unit: {
    value: 3
  }
}
const objectB = {
  goo: 'go',
  no: '1',
  unit: {
    name: 'kilo',
    value: 1
  }
}

compare(objectA, objectB)
// return value
//{
//  missingKeys: ['goo'],
//  subObjects: {
//    unit: {
//      missingKeys: ['name']
//    }
//  }
//}

Command line

compare can be used in command line also. It takes two paths to json or js file (that exports object). Outputs result as a stringified json.

Command:

object-compare [path to json/js object] [path to reference json/js object]

TODO:

  • clean command line output
0.1.0

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago