0.1.0 • Published 5 years ago
object-key-compare v0.1.0
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
- compareObject: object that is being tested
- 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