https://github.com/beyondjs/equal
A lightweight and efficient deep equality comparison utility for JavaScript. This package provides flexible comparison of primitive values, arrays, and objects, including nested structures. Supports order-insensitive comparisons and handles circular references, making it ideal for complex data equality checks in various JavaScript environments.
https://github.com/beyondjs/equal
Last synced: 6 months ago
JSON representation
A lightweight and efficient deep equality comparison utility for JavaScript. This package provides flexible comparison of primitive values, arrays, and objects, including nested structures. Supports order-insensitive comparisons and handles circular references, making it ideal for complex data equality checks in various JavaScript environments.
- Host: GitHub
- URL: https://github.com/beyondjs/equal
- Owner: beyondjs
- License: mit
- Created: 2022-12-01T13:30:17.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-08-13T22:04:01.000Z (10 months ago)
- Last Synced: 2025-08-14T03:44:07.870Z (10 months ago)
- Language: TypeScript
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @beyond-js/equal
A flexible deep equality comparison utility for JavaScript objects and arrays.
## Installation
```bash
npm install @beyond-js/equal
```
## Usage
```javascript
const equal = require('@beyond-js/equal');
// Compare primitive values
console.log(equal(1, 1)); // true
console.log(equal('a', 'b')); // false
// Compare arrays
console.log(equal([1, 2, 3], [1, 2, 3])); // true
console.log(equal([1, 2, 3], [3, 2, 1])); // false
// Compare objects
console.log(equal({ a: 1, b: 2 }, { b: 2, a: 1 })); // true
console.log(equal({ a: 1, b: 2 }, { a: 1, b: 3 })); // false
// Compare nested structures
console.log(equal({ a: [1, { b: 2 }] }, { a: [1, { b: 2 }] })); // true
```
## API
### `equal(value1, value2)`
Compares two values for deep equality.
- `value1`, `value2`: The values to compare. Can be primitives, arrays, or objects.
- Returns: `boolean` - `true` if the values are deeply equal, `false` otherwise.
### `equal.generate(value)`
Generates a comparable string representation of a value.
- `value`: The value to generate a comparable representation for.
- Returns: `string` - A JSON string representation of the value, with arrays and object properties sorted.
## Features
- Deep equality comparison for nested objects and arrays
- Order-insensitive comparison for object properties and array elements
- Handles circular references
- Lightweight with no external dependencies
## License
MIT © [[BeyondJS](https://beyondjs)]