-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
d697c35
commit e0b3571
Showing
28 changed files
with
156 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ cefc | |
codecov | ||
commitlintrc | ||
dedupe | ||
dequal | ||
dessant | ||
dohm | ||
fbca | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @file Unit Tests - equal | ||
* @module tutils/utils/tests/unit/equal | ||
*/ | ||
|
||
import INTEGER from '#fixtures/integer' | ||
import testSubject from '../equal' | ||
|
||
describe('unit:utils/equal', () => { | ||
it('should return false if a and b are not deeply equal', () => { | ||
// Arrange | ||
const cases: Parameters<typeof testSubject>[] = [ | ||
[{}, { value: faker.number.int() }], | ||
[[], [faker.number.int(), faker.number.int(), faker.number.int()]], | ||
[INTEGER, INTEGER * -1], | ||
[faker.date.future(), faker.date.past()] | ||
] | ||
|
||
// Act + Expect | ||
cases.forEach(([a, b]) => expect(testSubject(a, b)).to.be.false) | ||
}) | ||
|
||
it('should return true if a and b are deeply equal', () => { | ||
// Arrange | ||
const cases: Parameters<typeof testSubject>[] = [ | ||
[{ value: INTEGER }, { value: INTEGER }], | ||
[[INTEGER], [INTEGER]], | ||
[INTEGER, INTEGER], | ||
[new Date(), new Date()], | ||
[new Date(), new Date(), value => (value as Date).getTime()] | ||
] | ||
|
||
// Act + Expect | ||
cases.forEach(([a, b, identity]) => { | ||
expect(testSubject(a, b, identity)).to.be.true | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @file Utilities - equal | ||
* @module tutils/utils/equal | ||
*/ | ||
|
||
import type { Fn, IndexSignature, Nilable, NumberString } from '#src/types' | ||
import { dequal } from 'dequal' | ||
import isFunction from './is-function' | ||
|
||
/** | ||
* Returns a boolean indicating if values `a` and `b` are deeply equal. | ||
* | ||
* An `identity` function can be used to convert either value to a unique key. | ||
* If provided, items with the same identity key will be considered equal. | ||
* | ||
* @see https://github.com/lukeed/dequal | ||
* | ||
* @template A - First comparison value type | ||
* @template B - Second comparison value type | ||
* @template K - Identity key type | ||
* | ||
* @param {unknown} a - First comparison value | ||
* @param {unknown} b - Second comparison value | ||
* @param {Nilable<Fn<[A | B], K>>} [identity] - Identity key function | ||
* @return {boolean} `true` if `a` and `b` are deeply equal | ||
*/ | ||
function equal<A, B, K extends IndexSignature = NumberString>( | ||
a: A, | ||
b: B, | ||
identity?: Nilable<Fn<[A | B], K>> | ||
): boolean { | ||
return isFunction(identity) ? dequal(identity(a), identity(b)) : dequal(a, b) | ||
} | ||
|
||
export default equal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.