TreasureTrails/node_modules/remeda/dist/isShallowEqual.cjs.map

1 line
6 KiB
Text
Raw Permalink Normal View History

2026-03-18 09:02:21 -05:00
{"version":3,"file":"isShallowEqual.cjs","names":["purry"],"sources":["../src/isShallowEqual.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\n/**\n * Performs a *shallow structural* comparison between two values to determine if\n * they are equivalent. For primitive values this is equivalent to `===`, for\n * arrays a **strict equality** check would be performed on every item, in\n * order, and for objects props will be matched and checked for **strict\n * equality**; Unlike `isDeepEqual` where the function also *recurses* into each\n * item and value.\n *\n * !IMPORTANT: symbol properties of objects are not supported right now and\n * might result in unexpected behavior. Please open an issue in the Remeda\n * github project if you need support for these types.\n *\n * !IMPORTANT: Promise, Date, and RegExp, are shallowly equal, even when they\n * are semantically different (e.g. resolved promises); but `isDeepEqual` does\n * compare the latter 2 semantically by-value.\n *\n * The result would be narrowed to the second value so that the function can be\n * used as a type guard.\n *\n * See:\n * - `isStrictEqual` if you don't need a deep comparison and just want to check\n * for simple (`===`, `Object.is`) equality.\n * - `isDeepEqual` for a recursively deep check of arrays and objects.\n *\n * @param data - The first value to compare.\n * @param other - The second value to compare.\n * @signature\n * R.isShallowEqual(data, other)\n * @example\n * R.isShallowEqual(1, 1) //=> true\n * R.isShallowEqual(1, '1') //=> false\n * R.isShallowEqual([1, 2, 3], [1, 2, 3]) //=> true\n * R.isShallowEqual([[1], [2], [3]], [[1], [2], [3]]) //=> false\n * @dataFirst\n * @category Guard\n */\nexport function isShallowEqual<T, S extends T>(\n data: T,\n other: T extends Exclude<T, S> ? S : never,\n): data is S;\nexport function isShallowEqual<T>(data: T, other: T): boolean;\n\n/**\n * Performs a *shallow structural* comparison between two values to determine if\n * they are equivalent. For primitive values this is equivalent to `===`, for\n * arrays a **strict equality** check would be performed on every item, in\n * order, and for objects props will be matched and checked for **strict\n * equality**; Unlike `isDeepEqual` where the function also *recurses* into each\n * item and value.\n *\n * !IMPORTANT: symbol properties of objects are not supported right now and\n * might result in unexpected behavior. Please open an issue in the Remeda\n * github project if you need support for these types.\n *\n * !IMPORTANT: All built-in objects (Promise, Date, RegExp) are shallowly equal,\n * even when they are semantically different (e.g. resolved promises). Use\n * `isDeepEqual` instead.\n *\n * The result would be narrowed to the second value so that the function can be\n * used as a type guard.\n *\n * See:\n * - `isStrictEqual` if you don't need a deep comparison and just want to check\n * for simple (`===`, `Object.is`) equality.\n * - `isDeepEqual` for a recursively deep check of arrays and objects.\n *\n * @param other - The second value to compare.\n * @signature\n * R.isShallowEqual(other)(data)\n * @example\n * R.pipe(1, R.isShallowEqual(1)) //=> true\n * R.pipe(1, R.isShallowEqual('1')) //=> false\n * R.pipe([1, 2, 3], R.isShallowEqual([1, 2, 3])) //=> true\n * R.pipe([[1], [2], [3]], R.isShallowEqual([[1], [2], [3]])) //=> false\n * @dataFirst\n * @category Guard\n */\nexport function isShallowEqual<T, S extends T>(\n other: T extends Exclude<T, S> ? S : never,\n): (data: T) => data is S;\nexport function isShallowEqual<T>(other: T): (data: T) => boolean;\n\nexport function isShallowEqual(...args: readonly unknown[]): unknown {\n return purry(isShallowEqualImplementation, args);\n}\n\nfunction isShallowEqualImplementation<T>(a: T, b: T): boolean {\n if (a === b || Object.is(a, b)) {\n return true;\n }\n\n if (\n typeof a !== \"object\" ||\n a === null ||\n typeof b !== \"object\" ||\n b === null\n ) {\n return false;\n }\n\n if (a instanceof Map && b instanceof Map)