@x-oasis/shallow-equal 0.1.19 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/shallow-equal.cjs.development.js +4 -6
- package/dist/shallow-equal.cjs.development.js.map +1 -1
- package/dist/shallow-equal.cjs.production.min.js +1 -1
- package/dist/shallow-equal.cjs.production.min.js.map +1 -1
- package/dist/shallow-equal.esm.js +2 -6
- package/dist/shallow-equal.esm.js.map +1 -1
- package/package.json +4 -1
- package/src/index.ts +1 -26
- package/test/test.spec.ts +9 -3
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
+
|
|
7
|
+
var is = _interopDefault(require('@x-oasis/is'));
|
|
8
|
+
|
|
5
9
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
6
|
-
function is(x, y) {
|
|
7
|
-
if (x === y) {
|
|
8
|
-
return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
|
9
|
-
}
|
|
10
|
-
return x !== x && y !== y;
|
|
11
|
-
}
|
|
12
10
|
function shallowEqual(objA, objB) {
|
|
13
11
|
if (is(objA, objB)) {
|
|
14
12
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shallow-equal.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["// https://github.com/facebook/react/blob/144328fe81719e916b946e22660479e31561bb0b/packages/shared/shallowEqual.js#L36-L68\n\
|
|
1
|
+
{"version":3,"file":"shallow-equal.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["// https://github.com/facebook/react/blob/144328fe81719e916b946e22660479e31561bb0b/packages/shared/shallowEqual.js#L36-L68\n\nimport is from '@x-oasis/is';\n\nconst hasOwnProperty = Object.prototype.hasOwnProperty;\n\n/**\n * Performs equality by iterating through keys on an object and returning false\n * when any key has values which are not strictly equal between the arguments.\n * Returns true when the values of all keys are strictly equal.\n */\nfunction shallowEqual(objA: any, objB: any) {\n if (is(objA, objB)) {\n return true;\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false;\n }\n\n const keysA = Object.keys(objA);\n const keysB = Object.keys(objB);\n\n if (keysA.length !== keysB.length) {\n return false;\n }\n\n // Test for A's keys different from B.\n for (let i = 0; i < keysA.length; i++) {\n if (\n !hasOwnProperty.call(objB, keysA[i]) ||\n !is(objA[keysA[i]], objB[keysA[i]])\n ) {\n return false;\n }\n }\n\n return true;\n}\n\nexport default shallowEqual;\n"],"names":["hasOwnProperty","Object","prototype","shallowEqual","objA","objB","is","keysA","keys","keysB","length","i","call"],"mappings":";;;;;;;;AAIA,IAAMA,cAAc,GAAGC,MAAM,CAACC,SAAS,CAACF,cAAc;AAOtD,SAASG,YAAYA,CAACC,IAAS,EAAEC,IAAS;EACxC,IAAIC,EAAE,CAACF,IAAI,EAAEC,IAAI,CAAC,EAAE;IAClB,OAAO,IAAI;;EAGb,IACE,OAAOD,IAAI,KAAK,QAAQ,IACxBA,IAAI,KAAK,IAAI,IACb,OAAOC,IAAI,KAAK,QAAQ,IACxBA,IAAI,KAAK,IAAI,EACb;IACA,OAAO,KAAK;;EAGd,IAAME,KAAK,GAAGN,MAAM,CAACO,IAAI,CAACJ,IAAI,CAAC;EAC/B,IAAMK,KAAK,GAAGR,MAAM,CAACO,IAAI,CAACH,IAAI,CAAC;EAE/B,IAAIE,KAAK,CAACG,MAAM,KAAKD,KAAK,CAACC,MAAM,EAAE;IACjC,OAAO,KAAK;;EAId,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGJ,KAAK,CAACG,MAAM,EAAEC,CAAC,EAAE,EAAE;IACrC,IACE,CAACX,cAAc,CAACY,IAAI,CAACP,IAAI,EAAEE,KAAK,CAACI,CAAC,CAAC,CAAC,IACpC,CAACL,EAAE,CAACF,IAAI,CAACG,KAAK,CAACI,CAAC,CAAC,CAAC,EAAEN,IAAI,CAACE,KAAK,CAACI,CAAC,CAAC,CAAC,CAAC,EACnC;MACA,OAAO,KAAK;;;EAIhB,OAAO,IAAI;AACb;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("@x-oasis/is"))&&"object"==typeof e&&"default"in e?e.default:e,r=Object.prototype.hasOwnProperty;exports.default=function(e,o){if(t(e,o))return!0;if("object"!=typeof e||null===e||"object"!=typeof o||null===o)return!1;var n=Object.keys(e),u=Object.keys(o);if(n.length!==u.length)return!1;for(var l=0;l<n.length;l++)if(!r.call(o,n[l])||!t(e[n[l]],o[n[l]]))return!1;return!0};
|
|
2
2
|
//# sourceMappingURL=shallow-equal.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shallow-equal.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["// https://github.com/facebook/react/blob/144328fe81719e916b946e22660479e31561bb0b/packages/shared/shallowEqual.js#L36-L68\n\
|
|
1
|
+
{"version":3,"file":"shallow-equal.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["// https://github.com/facebook/react/blob/144328fe81719e916b946e22660479e31561bb0b/packages/shared/shallowEqual.js#L36-L68\n\nimport is from '@x-oasis/is';\n\nconst hasOwnProperty = Object.prototype.hasOwnProperty;\n\n/**\n * Performs equality by iterating through keys on an object and returning false\n * when any key has values which are not strictly equal between the arguments.\n * Returns true when the values of all keys are strictly equal.\n */\nfunction shallowEqual(objA: any, objB: any) {\n if (is(objA, objB)) {\n return true;\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false;\n }\n\n const keysA = Object.keys(objA);\n const keysB = Object.keys(objB);\n\n if (keysA.length !== keysB.length) {\n return false;\n }\n\n // Test for A's keys different from B.\n for (let i = 0; i < keysA.length; i++) {\n if (\n !hasOwnProperty.call(objB, keysA[i]) ||\n !is(objA[keysA[i]], objB[keysA[i]])\n ) {\n return false;\n }\n }\n\n return true;\n}\n\nexport default shallowEqual;\n"],"names":["hasOwnProperty","Object","prototype","objA","objB","is","keysA","keys","keysB","length","i","call"],"mappings":"sJAIMA,EAAiBC,OAAOC,UAAUF,+BAOxC,SAAsBG,EAAWC,GAC/B,GAAIC,EAAGF,EAAMC,GACX,OAAO,EAGT,GACkB,iBAATD,GACE,OAATA,GACgB,iBAATC,GACE,OAATA,EAEA,OAAO,EAGT,IAAME,EAAQL,OAAOM,KAAKJ,GACpBK,EAAQP,OAAOM,KAAKH,GAE1B,GAAIE,EAAMG,SAAWD,EAAMC,OACzB,OAAO,EAIT,IAAK,IAAIC,EAAI,EAAGA,EAAIJ,EAAMG,OAAQC,IAChC,IACGV,EAAeW,KAAKP,EAAME,EAAMI,MAChCL,EAAGF,EAAKG,EAAMI,IAAKN,EAAKE,EAAMI,KAE/B,OAAO,EAIX,OAAO"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
+
import is from '@x-oasis/is';
|
|
2
|
+
|
|
1
3
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2
|
-
function is(x, y) {
|
|
3
|
-
if (x === y) {
|
|
4
|
-
return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
|
5
|
-
}
|
|
6
|
-
return x !== x && y !== y;
|
|
7
|
-
}
|
|
8
4
|
function shallowEqual(objA, objB) {
|
|
9
5
|
if (is(objA, objB)) {
|
|
10
6
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shallow-equal.esm.js","sources":["../src/index.ts"],"sourcesContent":["// https://github.com/facebook/react/blob/144328fe81719e916b946e22660479e31561bb0b/packages/shared/shallowEqual.js#L36-L68\n\
|
|
1
|
+
{"version":3,"file":"shallow-equal.esm.js","sources":["../src/index.ts"],"sourcesContent":["// https://github.com/facebook/react/blob/144328fe81719e916b946e22660479e31561bb0b/packages/shared/shallowEqual.js#L36-L68\n\nimport is from '@x-oasis/is';\n\nconst hasOwnProperty = Object.prototype.hasOwnProperty;\n\n/**\n * Performs equality by iterating through keys on an object and returning false\n * when any key has values which are not strictly equal between the arguments.\n * Returns true when the values of all keys are strictly equal.\n */\nfunction shallowEqual(objA: any, objB: any) {\n if (is(objA, objB)) {\n return true;\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false;\n }\n\n const keysA = Object.keys(objA);\n const keysB = Object.keys(objB);\n\n if (keysA.length !== keysB.length) {\n return false;\n }\n\n // Test for A's keys different from B.\n for (let i = 0; i < keysA.length; i++) {\n if (\n !hasOwnProperty.call(objB, keysA[i]) ||\n !is(objA[keysA[i]], objB[keysA[i]])\n ) {\n return false;\n }\n }\n\n return true;\n}\n\nexport default shallowEqual;\n"],"names":["hasOwnProperty","Object","prototype","shallowEqual","objA","objB","is","keysA","keys","keysB","length","i","call"],"mappings":";;AAIA,IAAMA,cAAc,GAAGC,MAAM,CAACC,SAAS,CAACF,cAAc;AAOtD,SAASG,YAAYA,CAACC,IAAS,EAAEC,IAAS;EACxC,IAAIC,EAAE,CAACF,IAAI,EAAEC,IAAI,CAAC,EAAE;IAClB,OAAO,IAAI;;EAGb,IACE,OAAOD,IAAI,KAAK,QAAQ,IACxBA,IAAI,KAAK,IAAI,IACb,OAAOC,IAAI,KAAK,QAAQ,IACxBA,IAAI,KAAK,IAAI,EACb;IACA,OAAO,KAAK;;EAGd,IAAME,KAAK,GAAGN,MAAM,CAACO,IAAI,CAACJ,IAAI,CAAC;EAC/B,IAAMK,KAAK,GAAGR,MAAM,CAACO,IAAI,CAACH,IAAI,CAAC;EAE/B,IAAIE,KAAK,CAACG,MAAM,KAAKD,KAAK,CAACC,MAAM,EAAE;IACjC,OAAO,KAAK;;EAId,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGJ,KAAK,CAACG,MAAM,EAAEC,CAAC,EAAE,EAAE;IACrC,IACE,CAACX,cAAc,CAACY,IAAI,CAACP,IAAI,EAAEE,KAAK,CAACI,CAAC,CAAC,CAAC,IACpC,CAACL,EAAE,CAACF,IAAI,CAACG,KAAK,CAACI,CAAC,CAAC,CAAC,EAAEN,IAAI,CAACE,KAAK,CAACI,CAAC,CAAC,CAAC,CAAC,EACnC;MACA,OAAO,KAAK;;;EAIhB,OAAO,IAAI;AACb;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-oasis/shallow-equal",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "shallow equal function",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"tsdx": "^0.14.1"
|
|
12
12
|
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@x-oasis/is": "^0.1.19"
|
|
15
|
+
},
|
|
13
16
|
"scripts": {
|
|
14
17
|
"build": "tsdx build --tsconfig tsconfig.build.json",
|
|
15
18
|
"clean": "rimraf ./dist",
|
package/src/index.ts
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
// https://github.com/facebook/react/blob/144328fe81719e916b946e22660479e31561bb0b/packages/shared/shallowEqual.js#L36-L68
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @flow
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/* eslint-disable no-self-compare */
|
|
3
|
+
import is from '@x-oasis/is';
|
|
13
4
|
|
|
14
5
|
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
15
6
|
|
|
16
|
-
/**
|
|
17
|
-
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
18
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
19
|
-
*/
|
|
20
|
-
function is(x: any, y: any) {
|
|
21
|
-
// SameValue algorithm
|
|
22
|
-
if (x === y) {
|
|
23
|
-
// Steps 1-5, 7-10
|
|
24
|
-
// Steps 6.b-6.e: +0 != -0
|
|
25
|
-
// Added the nonzero y check to make Flow happy, but it is redundant
|
|
26
|
-
return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
|
27
|
-
}
|
|
28
|
-
// Step 6.a: NaN == NaN
|
|
29
|
-
return x !== x && y !== y;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
7
|
/**
|
|
33
8
|
* Performs equality by iterating through keys on an object and returning false
|
|
34
9
|
* when any key has values which are not strictly equal between the arguments.
|
package/test/test.spec.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { expect, test } from 'vitest'
|
|
1
|
+
import { expect, test } from 'vitest';
|
|
2
|
+
import shallowEqual from '../src';
|
|
2
3
|
|
|
3
4
|
test('vitest', async () => {
|
|
4
|
-
expect(
|
|
5
|
-
|
|
5
|
+
expect(shallowEqual([1, 2], [1, 2])).toBe(true);
|
|
6
|
+
expect(shallowEqual([1, 2], [2, 1])).toBe(false);
|
|
7
|
+
expect(shallowEqual(1, 1)).toBe(true);
|
|
8
|
+
expect(shallowEqual(NaN, NaN)).toBe(true);
|
|
9
|
+
expect(shallowEqual(null, null)).toBe(true);
|
|
10
|
+
expect(shallowEqual(undefined, undefined)).toBe(true);
|
|
11
|
+
});
|