Files
povtornyy-ekzamen-2-sravnit…/README.md
T

54 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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 dotseparated path to the differing property.
- `values`: An array of the values from the three objects in the order `[a, b, c]`.
## Installation
```bash
npm install compare-three-entities
```
## Usage
```js
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:
```bash
npm test
```
The tests cover basic equality, toplevel differences, nested differences, and missing keys.
## License
MIT