(c: unknown, d: unknown, options?: EqualOptions)
| 40 | * @param options for the equality check |
| 41 | */ |
| 42 | export function equal(c: unknown, d: unknown, options?: EqualOptions): boolean { |
| 43 | const { customTesters = [], strictCheck } = options ?? {}; |
| 44 | const seen = new Map(); |
| 45 | |
| 46 | return (function compare(a: unknown, b: unknown): boolean { |
| 47 | const asymmetric = asymmetricEqual(a, b); |
| 48 | if (asymmetric !== undefined) { |
| 49 | return asymmetric; |
| 50 | } |
| 51 | |
| 52 | if (customTesters?.length) { |
| 53 | for (const customTester of customTesters) { |
| 54 | const testContext = { |
| 55 | equal, |
| 56 | }; |
| 57 | const pass = customTester.call(testContext, a, b, customTesters); |
| 58 | if (pass !== undefined) { |
| 59 | return pass; |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Have to render RegExp & Date for string comparison |
| 65 | // unless it's mistreated as object |
| 66 | if ( |
| 67 | a && |
| 68 | b && |
| 69 | ((a instanceof RegExp && b instanceof RegExp) || |
| 70 | (a instanceof URL && b instanceof URL)) |
| 71 | ) { |
| 72 | return String(a) === String(b); |
| 73 | } |
| 74 | |
| 75 | if (a instanceof Date && b instanceof Date) { |
| 76 | const aTime = a.getTime(); |
| 77 | const bTime = b.getTime(); |
| 78 | // Check for NaN equality manually since NaN is not |
| 79 | // equal to itself. |
| 80 | if (Number.isNaN(aTime) && Number.isNaN(bTime)) { |
| 81 | return true; |
| 82 | } |
| 83 | return aTime === bTime; |
| 84 | } |
| 85 | if (a instanceof Error && b instanceof Error) { |
| 86 | return a.message === b.message; |
| 87 | } |
| 88 | if (typeof a === "number" && typeof b === "number") { |
| 89 | return Number.isNaN(a) && Number.isNaN(b) || a === b; |
| 90 | } |
| 91 | if (a === null || b === null) { |
| 92 | return a === b; |
| 93 | } |
| 94 | const className = Object.prototype.toString.call(a); |
| 95 | if (className !== Object.prototype.toString.call(b)) { |
| 96 | return false; |
| 97 | } |
| 98 | if (Object.is(a, b)) { |
| 99 | return true; |
no test coverage detected