| 1 | /**
|
|---|
| 2 | * Compares two values for equality using a custom comparison function.
|
|---|
| 3 | *
|
|---|
| 4 | * The custom function allows for fine-tuned control over the comparison process. If it returns a boolean, that result determines the equality. If it returns undefined, the function falls back to the default equality comparison.
|
|---|
| 5 | *
|
|---|
| 6 | * This function also uses the custom equality function to compare values inside objects,
|
|---|
| 7 | * arrays, maps, sets, and other complex structures, ensuring a deep comparison.
|
|---|
| 8 | *
|
|---|
| 9 | * This approach provides flexibility in handling complex comparisons while maintaining efficient default behavior for simpler cases.
|
|---|
| 10 | *
|
|---|
| 11 | * The custom comparison function can take up to six parameters:
|
|---|
| 12 | * - `x`: The value from the first object `a`.
|
|---|
| 13 | * - `y`: The value from the second object `b`.
|
|---|
| 14 | * - `property`: The property key used to get `x` and `y`.
|
|---|
| 15 | * - `xParent`: The parent of the first value `x`.
|
|---|
| 16 | * - `yParent`: The parent of the second value `y`.
|
|---|
| 17 | * - `stack`: An internal stack (Map) to handle circular references.
|
|---|
| 18 | *
|
|---|
| 19 | * @param {unknown} a - The first value to compare.
|
|---|
| 20 | * @param {unknown} b - The second value to compare.
|
|---|
| 21 | * @param {(x: any, y: any, property?: PropertyKey, xParent?: any, yParent?: any, stack?: Map<any, any>) => boolean | void} areValuesEqual - A function to customize the comparison.
|
|---|
| 22 | * If it returns a boolean, that result will be used. If it returns undefined,
|
|---|
| 23 | * the default equality comparison will be used.
|
|---|
| 24 | * @returns {boolean} `true` if the values are equal according to the customizer, otherwise `false`.
|
|---|
| 25 | *
|
|---|
| 26 | * @example
|
|---|
| 27 | * const customizer = (a, b) => {
|
|---|
| 28 | * if (typeof a === 'string' && typeof b === 'string') {
|
|---|
| 29 | * return a.toLowerCase() === b.toLowerCase();
|
|---|
| 30 | * }
|
|---|
| 31 | * };
|
|---|
| 32 | * isEqualWith('Hello', 'hello', customizer); // true
|
|---|
| 33 | * isEqualWith({ a: 'Hello' }, { a: 'hello' }, customizer); // true
|
|---|
| 34 | * isEqualWith([1, 2, 3], [1, 2, 3], customizer); // true
|
|---|
| 35 | */
|
|---|
| 36 | declare function isEqualWith(a: any, b: any, areValuesEqual: (x: any, y: any, property?: PropertyKey, xParent?: any, yParent?: any, stack?: Map<any, any>) => boolean | void): boolean;
|
|---|
| 37 |
|
|---|
| 38 | export { isEqualWith };
|
|---|