@guanghechen/equal 1.0.0-alpha.1
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/CHANGELOG.md +18 -0
- package/README.md +70 -0
- package/lib/cjs/index.cjs +52 -0
- package/lib/esm/index.mjs +47 -0
- package/lib/types/index.d.ts +10 -0
- package/package.json +55 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# 1.0.0-alpha.1 (2023-10-04)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* ✨ add @guanghechen/equal (migrited from @guanghechen/fast-deep-equal) ([4ae8c7d](https://github.com/guanghechen/sora/commit/4ae8c7de7f7bc94ef4d0ad352950e54d03dfd321))
|
|
12
|
+
* ✨ add @guanghechen/error.types ([3088ad3](https://github.com/guanghechen/sora/commit/3088ad314ff7ebe4a5bf4bfa51d8303cad40df89))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Performance Improvements
|
|
16
|
+
|
|
17
|
+
* ⬆️ format codes and upgrade devDependencies ([6c6f382](https://github.com/guanghechen/sora/commit/6c6f382a0ac20e4c331778cc259f197d292f0eb3))
|
|
18
|
+
* ⬆️ the version of subpackage devDependencies is not matter ([3287c22](https://github.com/guanghechen/sora/commit/3287c22fb150af6620c1c9f6f4b186498aea815b))
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<header>
|
|
2
|
+
<h1 align="center">
|
|
3
|
+
<a href="https://github.com/guanghechen/sora/tree/@guanghechen/equal@1.0.0-alpha.1/packages/equal#readme">@guanghechen/equal</a>
|
|
4
|
+
</h1>
|
|
5
|
+
<div align="center">
|
|
6
|
+
<a href="https://www.npmjs.com/package/@guanghechen/equal">
|
|
7
|
+
<img
|
|
8
|
+
alt="Npm Version"
|
|
9
|
+
src="https://img.shields.io/npm/v/@guanghechen/equal.svg"
|
|
10
|
+
/>
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/@guanghechen/equal">
|
|
13
|
+
<img
|
|
14
|
+
alt="Npm Download"
|
|
15
|
+
src="https://img.shields.io/npm/dm/@guanghechen/equal.svg"
|
|
16
|
+
/>
|
|
17
|
+
</a>
|
|
18
|
+
<a href="https://www.npmjs.com/package/@guanghechen/equal">
|
|
19
|
+
<img
|
|
20
|
+
alt="Npm License"
|
|
21
|
+
src="https://img.shields.io/npm/l/@guanghechen/equal.svg"
|
|
22
|
+
/>
|
|
23
|
+
</a>
|
|
24
|
+
<a href="#install">
|
|
25
|
+
<img
|
|
26
|
+
alt="Module Formats: cjs, esm"
|
|
27
|
+
src="https://img.shields.io/badge/module_formats-cjs%2C%20esm-green.svg"
|
|
28
|
+
/>
|
|
29
|
+
</a>
|
|
30
|
+
<a href="https://github.com/nodejs/node">
|
|
31
|
+
<img
|
|
32
|
+
alt="Node.js Version"
|
|
33
|
+
src="https://img.shields.io/node/v/@guanghechen/equal"
|
|
34
|
+
/>
|
|
35
|
+
</a>
|
|
36
|
+
<a href="https://github.com/facebook/jest">
|
|
37
|
+
<img
|
|
38
|
+
alt="Tested with Jest"
|
|
39
|
+
src="https://img.shields.io/badge/tested_with-jest-9c465e.svg"
|
|
40
|
+
/>
|
|
41
|
+
</a>
|
|
42
|
+
<a href="https://github.com/prettier/prettier">
|
|
43
|
+
<img
|
|
44
|
+
alt="Code Style: prettier"
|
|
45
|
+
src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square"
|
|
46
|
+
/>
|
|
47
|
+
</a>
|
|
48
|
+
</div>
|
|
49
|
+
</header>
|
|
50
|
+
<br/>
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
Inspired by https://github.com/epoberezkin/fast-deep-equal, re-publish cause it's not support ESM.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
* use within ESM.
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
import isEqual from '@guanghechen/equal'
|
|
62
|
+
console.log(isEqual({foo: 'bar'}, {foo: 'bar'})); // true
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
* use within CommonJS.
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
const isEqual = require('@guanghechen/equal')
|
|
69
|
+
console.log(isEqual({foo: 'bar'}, {foo: 'bar'})); // true
|
|
70
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function isEqual(x, y) {
|
|
6
|
+
if (x === null || y === null)
|
|
7
|
+
return x === y;
|
|
8
|
+
if (x === undefined || y === undefined)
|
|
9
|
+
return x === y;
|
|
10
|
+
if (typeof x !== typeof y)
|
|
11
|
+
return false;
|
|
12
|
+
if (Object.is(x, y))
|
|
13
|
+
return true;
|
|
14
|
+
if (typeof x === 'object') {
|
|
15
|
+
if (x.constructor !== y.constructor)
|
|
16
|
+
return false;
|
|
17
|
+
if (Array.isArray(x)) {
|
|
18
|
+
if (x.length !== y.length)
|
|
19
|
+
return false;
|
|
20
|
+
for (let i = 0; i < x.length; ++i) {
|
|
21
|
+
if (!isEqual(x[i], y[i]))
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (x.constructor === RegExp)
|
|
27
|
+
return x.source === y.source && x.flags === y.flags;
|
|
28
|
+
if (x.valueOf !== Object.prototype.valueOf)
|
|
29
|
+
return x.valueOf() === y.valueOf();
|
|
30
|
+
if (x.toString !== Object.prototype.toString)
|
|
31
|
+
return x.toString() === y.toString();
|
|
32
|
+
const keys = Object.keys(x);
|
|
33
|
+
if (keys.length !== Object.keys(y).length)
|
|
34
|
+
return false;
|
|
35
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
36
|
+
if (!Object.prototype.hasOwnProperty.call(y, keys[i]))
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
40
|
+
const key = keys[i];
|
|
41
|
+
if (key === '_owner' && x.$$typeof)
|
|
42
|
+
continue;
|
|
43
|
+
if (!isEqual(x[key], y[key]))
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
exports.default = isEqual;
|
|
52
|
+
exports.isEqual = isEqual;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
function isEqual(x, y) {
|
|
2
|
+
if (x === null || y === null)
|
|
3
|
+
return x === y;
|
|
4
|
+
if (x === undefined || y === undefined)
|
|
5
|
+
return x === y;
|
|
6
|
+
if (typeof x !== typeof y)
|
|
7
|
+
return false;
|
|
8
|
+
if (Object.is(x, y))
|
|
9
|
+
return true;
|
|
10
|
+
if (typeof x === 'object') {
|
|
11
|
+
if (x.constructor !== y.constructor)
|
|
12
|
+
return false;
|
|
13
|
+
if (Array.isArray(x)) {
|
|
14
|
+
if (x.length !== y.length)
|
|
15
|
+
return false;
|
|
16
|
+
for (let i = 0; i < x.length; ++i) {
|
|
17
|
+
if (!isEqual(x[i], y[i]))
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
if (x.constructor === RegExp)
|
|
23
|
+
return x.source === y.source && x.flags === y.flags;
|
|
24
|
+
if (x.valueOf !== Object.prototype.valueOf)
|
|
25
|
+
return x.valueOf() === y.valueOf();
|
|
26
|
+
if (x.toString !== Object.prototype.toString)
|
|
27
|
+
return x.toString() === y.toString();
|
|
28
|
+
const keys = Object.keys(x);
|
|
29
|
+
if (keys.length !== Object.keys(y).length)
|
|
30
|
+
return false;
|
|
31
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
32
|
+
if (!Object.prototype.hasOwnProperty.call(y, keys[i]))
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
36
|
+
const key = keys[i];
|
|
37
|
+
if (key === '_owner' && x.$$typeof)
|
|
38
|
+
continue;
|
|
39
|
+
if (!isEqual(x[key], y[key]))
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { isEqual as default, isEqual };
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@guanghechen/equal",
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
|
+
"description": "The fastest deep equal with ES6 Map, Set and Typed arrays support.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "guanghechen",
|
|
7
|
+
"url": "https://github.com/guanghechen/"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/guanghechen/sora/tree/@guanghechen/equal@1.0.0-alpha.0",
|
|
12
|
+
"directory": "packages/equal"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/equal@1.0.0-alpha.0/packages/equal#readme",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"equal",
|
|
17
|
+
"fast deep equal"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"source": "./src/index.ts",
|
|
23
|
+
"import": "./lib/esm/index.mjs",
|
|
24
|
+
"require": "./lib/cjs/index.cjs",
|
|
25
|
+
"types": "./lib/types/index.d.ts"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"source": "./src/index.ts",
|
|
29
|
+
"main": "./lib/cjs/index.cjs",
|
|
30
|
+
"module": "./lib/esm/index.mjs",
|
|
31
|
+
"types": "./lib/types/index.d.ts",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">= 16.0.0"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"lib/",
|
|
38
|
+
"!lib/**/*.map",
|
|
39
|
+
"package.json",
|
|
40
|
+
"CHANGELOG.md",
|
|
41
|
+
"LICENSE",
|
|
42
|
+
"README.md"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "rimraf lib/ && cross-env NODE_ENV=production rollup -c ../../rollup.config.mjs",
|
|
46
|
+
"prepublishOnly": "yarn build",
|
|
47
|
+
"test": "node --experimental-vm-modules ../../node_modules/.bin/jest --config ../../jest.config.mjs --rootDir ."
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"cross-env": "*",
|
|
51
|
+
"rimraf": "*",
|
|
52
|
+
"rollup": "*"
|
|
53
|
+
},
|
|
54
|
+
"gitHead": "1cf773876cf6769b58cc08bdd77b74e22e3feabe"
|
|
55
|
+
}
|