https://github.com/oprogramador/deep-equal-in-any-order
A chai plugin to match objects and arrays deep equality with arrays (including nested ones) being in any order.
https://github.com/oprogramador/deep-equal-in-any-order
Last synced: 12 months ago
JSON representation
A chai plugin to match objects and arrays deep equality with arrays (including nested ones) being in any order.
- Host: GitHub
- URL: https://github.com/oprogramador/deep-equal-in-any-order
- Owner: oprogramador
- License: mit
- Created: 2017-11-11T14:42:38.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-06-28T10:59:09.000Z (12 months ago)
- Last Synced: 2025-06-28T11:39:59.919Z (12 months ago)
- Language: JavaScript
- Homepage:
- Size: 381 KB
- Stars: 16
- Watchers: 3
- Forks: 8
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# deep-equal-in-any-order
[](https://opensource.org/licenses/MIT)
[](https://travis-ci.com/oprogramador/deep-equal-in-any-order
)
[](https://npmjs.org/package/deep-equal-in-any-order
)
[Chai](https://www.chaijs.com/) plugin to match objects and arrays deep equality with arrays (including nested ones) being in any order.
It works in similar way as `deep.equal` but it doesn't checks the arrays order (at any level of nested objects and arrays). The array elements can be any JS entity (boolean, null, number, string, object, array...).
## install
```
npm i --save deep-equal-in-any-order
```
or
```
yarn add deep-equal-in-any-order
```
## usage
### `expect`
```js
const deepEqualInAnyOrder = require('deep-equal-in-any-order');
const chai = require('chai');
chai.use(deepEqualInAnyOrder);
const { expect } = chai;
expect([1, 2]).to.deep.equalInAnyOrder([2, 1]);
expect([1, 2]).to.not.deep.equalInAnyOrder([2, 1, 3]);
expect({ foo: [1, 2], bar: [4, 89, 22] }).to.deep.equalInAnyOrder({ foo: [2, 1], bar: [4, 22, 89] });
expect({ foo: ['foo-1', 'foo-2', [1, 2], null ] }).to.deep.equalInAnyOrder({ foo: [null, [1, 2], 'foo-1', 'foo-2'] });
expect({ foo: [1, 2], bar: { baz: ['a', 'b', { lorem: [5, 6] }] } }).to.deep.equalInAnyOrder({ foo: [2, 1], bar: { baz: ['b', 'a', { lorem: [6, 5] }] } });
```
### `assert`
```js
const deepEqualInAnyOrder = require('deep-equal-in-any-order');
const chai = require('chai');
chai.use(deepEqualInAnyOrder);
const { assert } = chai;
assert.deepEqualInAnyOrder([1, 2], [2, 1]);
assert.notDeepEqualInAnyOrder(1, 2], [2, 1, 3]);
assert.deepEqualInAnyOrder({ foo: [1, 2], bar: [4, 89, 22] }, { foo: [2, 1], bar: [4, 22, 89] });
assert.deepEqualInAnyOrder({ foo: ['foo-1', 'foo-2', [1, 2], null ] }, { foo: [null, [1, 2], 'foo-1', 'foo-2'] });
assert.deepEqualInAnyOrder({ foo: [1, 2], bar: { baz: ['a', 'b', { lorem: [5, 6] }] } }, { foo: [2, 1], bar: { baz: ['b', 'a', { lorem: [6, 5] }] } });
```