Compare Three Entities

A small utility library that compares three JavaScript objects and reports the differences between them.
The comparison is deep, meaning nested objects are compared recursively. The result is an array of difference objects, each containing:

  • key: The dot‑separated path to the differing property.
  • values: An array of the values from the three objects in the order [a, b, c].

Installation

npm install compare-three-entities

Usage

const compare = require('compare-three-entities');

const a = { name: 'Alice', age: 30, address: { city: 'NY' } };
const b = { name: 'Alice', age: 31, address: { city: 'NY' } };
const c = { name: 'Alice', age: 30, address: { city: 'LA' } };

const differences = compare(a, b, c);
console.log(differences);
// [
//   { key: 'age', values: [30, 31, 30] },
//   { key: 'address.city', values: ['NY', 'NY', 'LA'] }
// ]

API

compare(a, b, c)

  • Parameters:
    • a – First object.
    • b – Second object.
    • c – Third object.
  • Returns: Array – Sorted array of difference objects.

Testing

Run the test suite with:

npm test

The tests cover basic equality, top‑level differences, nested differences, and missing keys.

License

MIT

S
Description
BroJS: Повторный экзамен #2: Сравнительный обзор 3 сущностей (Tavily)
Readme
98 KiB
0 Stars 1 Watchers 0 Forks
Languages
JavaScript 50.2%
Python 46.2%
CSS 2.8%
HTML 0.8%