Skip to content

๐Ÿ” Finds difference between the keys of two objects

Notifications You must be signed in to change notification settings

diedsmiling/keys-diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

61 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

keys-diff

Build Status codecov

keys-diff is a javascript/node.js module that provides a tool for finding the difference between the keys of two objects.

NOTE: This module verifies just the identity of the objects keys, not the whole structure. For full investigation, you can use modules like deep-diff.

Install

Using npm:

$ npm install keys-diff

Or using yarn:

yarn add keys-diff

Usage

import keysDiff from 'keys-diff'
const foo = {
  foo: 'foo',
  bar: {
    baz: 'baz',
    qux: 'qux'
  }
};

const bar = {
  foo: 'foo',
  bar: {
    baz: 'baz',
    quux: 'quux'
  },
  corge: 'corge'
};

keysDiff(foo, bar);
/* => 
[ 
  [ 
    [ 'bar', 'qux' ] 
   ], 
   [ 
     [ 'bar', 'quux' ], 
     [ 'corge' ] 
   ] 
]
*/

NOTE: Function receives two objects as arguments and returns a multidimensional array. First element of the returned array includes all the keys (in a form of array describing the full path in depth) from the first object that are not included the second object. In its turn, second element of the returned array includes all the keys from the second object that are not included in the first one.

Use cases

I needed a similar tool when I came across an issue, where I needed to track the difference between two JSON files with l18n data from different branches. Could also be used to see the difference in API response structure, schemas and so on.

About

๐Ÿ” Finds difference between the keys of two objects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •