Sudoo-Compare

Build Status codecov npm version downloads

:beetle: A object comparison package

Install

yarn add @sudoo/compare
# Or
npm install @sudoo/compare --save

Usage

Compare two objects

import { compare, CompareResult } from "@sudoo/compare";

const firstObject: Record<string, string> = {
    foo: "bar",
};
const secondObject: Record<string, string> = {
    foo: "baz",
    extra: "extra",
};

const result: CompareResult[] = compare(firstObject, secondObject);

By running the able code, your result variable to get a list of result that indicate the difference between two objects.

[
  {
    keyStack: [ 'extra' ],
    keyString: 'extra',
    left: undefined,
    right: 'extra',
  },
  { 
    keyStack: [ 'foo' ],
    keyString: 'foo',
    left: 'bar',
    right: 'baz',
  },
]

If two objects are same, the result list will be empty.