UNPKG

remeda

Version:

A utility library for JavaScript and Typescript.

1 lines 3.7 kB
{"version":3,"file":"isStrictEqual.cjs","names":["purry"],"sources":["../src/isStrictEqual.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\n/**\n * Determines whether two values are *functionally identical* in all contexts.\n * For primitive values (string, number), this is done by-value, and for objects\n * it is done by-reference (i.e., they point to the same object in memory).\n *\n * Under the hood we use **both** the [`===` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality)\n * and [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is). This means that `isStrictEqual(NaN, NaN) === true`\n * (whereas `NaN !== NaN`), and `isStrictEqual(-0, 0) === true` (whereas\n * `Object.is(-0, 0) === false`).\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 * - `isDeepEqual` for a semantic comparison that allows comparing arrays and\n * objects \"by-value\", and recurses for every item.\n * - `isShallowEqual` if you need to compare arrays and objects \"by-value\" but\n * don't want to recurse into their values.\n *\n * @param data - The first value to compare.\n * @param other - The second value to compare.\n * @signature\n * R.isStrictEqual(data, other)\n * @example\n * R.isStrictEqual(1, 1) //=> true\n * R.isStrictEqual(1, '1') //=> false\n * R.isStrictEqual([1, 2, 3], [1, 2, 3]) //=> false\n * @dataFirst\n * @category Guard\n */\nexport function isStrictEqual<T, S extends T>(\n data: T,\n other: T extends Exclude<T, S> ? S : never,\n): data is S;\nexport function isStrictEqual<T>(data: T, other: T): boolean;\n\n/**\n * Determines whether two values are *functionally identical* in all contexts.\n * For primitive values (string, number), this is done by-value, and for objects\n * it is done by-reference (i.e., they point to the same object in memory).\n *\n * Under the hood we use **both** the [`===` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality)\n * and [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is). This means that `isStrictEqual(NaN, NaN) === true`\n * (whereas `NaN !== NaN`), and `isStrictEqual(-0, 0) === true` (whereas\n * `Object.is(-0, 0) === false`).\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 * - `isDeepEqual` for a semantic comparison that allows comparing arrays and\n * objects \"by-value\", and recurses for every item.\n * - `isShallowEqual` if you need to compare arrays and objects \"by-value\" but\n * don't want to recurse into their values.\n *\n * @param other - The second value to compare.\n * @signature\n * R.isStrictEqual(other)(data)\n * @example\n * R.pipe(1, R.isStrictEqual(1)); //=> true\n * R.pipe(1, R.isStrictEqual('1')); //=> false\n * R.pipe([1, 2, 3], R.isStrictEqual([1, 2, 3])); //=> false\n * @dataLast\n * @category Guard\n */\nexport function isStrictEqual<T, S extends T>(\n other: T extends Exclude<T, S> ? S : never,\n): (data: T) => data is S;\nexport function isStrictEqual<T>(other: T): (data: T) => boolean;\n\nexport function isStrictEqual(...args: ReadonlyArray<unknown>): unknown {\n return purry(isStrictlyEqualImplementation, args);\n}\n\nconst isStrictlyEqualImplementation = <T>(data: unknown, other: T): data is T =>\n data === other || Object.is(data, other);\n"],"mappings":"wCAwEA,SAAgB,EAAc,GAAG,EAAuC,CACtE,OAAOA,EAAAA,EAAM,EAA+B,EAAK,CAGnD,MAAM,GAAoC,EAAe,IACvD,IAAS,GAAS,OAAO,GAAG,EAAM,EAAM"}