UNPKG

@tienedev/datype

Version:

Modern TypeScript utility library with pragmatic typing and zero dependencies

48 lines 1.75 kB
/** * Performs a deep equality comparison between two values. * * @template T - The type of the first value * @template U - The type of the second value * @param a - The first value to compare * @param b - The second value to compare * @returns `true` if the values are deeply equal, `false` otherwise * * This function performs deep comparison for: * - Primitive values (using Object.is for NaN/±0 handling) * - Objects (comparing own enumerable properties recursively) * - Arrays (comparing elements recursively) * - Dates (comparing time values) * - RegExp (comparing source and flags) * - Set and Map (comparing contents) * - Functions (reference equality only) * - Circular references (handled safely) * * @example * ```typescript * import { isEqual } from 'datype'; * * // Primitive values * isEqual(1, 1); // true * isEqual('hello', 'hello'); // true * isEqual(NaN, NaN); // true (unlike === comparison) * isEqual(+0, -0); // false (unlike === comparison) * * // Objects * isEqual({ a: 1, b: 2 }, { a: 1, b: 2 }); // true * isEqual({ a: 1, b: 2 }, { b: 2, a: 1 }); // true (order doesn't matter) * isEqual({ a: { b: 1 } }, { a: { b: 1 } }); // true (deep comparison) * * // Arrays * isEqual([1, 2, 3], [1, 2, 3]); // true * isEqual([1, [2, 3]], [1, [2, 3]]); // true (deep comparison) * * // Dates * isEqual(new Date('2023-01-01'), new Date('2023-01-01')); // true * * // Mixed types * isEqual({ date: new Date('2023-01-01'), arr: [1, 2] }, * { date: new Date('2023-01-01'), arr: [1, 2] }); // true * ``` */ export declare function isEqual<T, U>(a: T, b: U): boolean; //# sourceMappingURL=index.d.ts.map