@thi.ng/equiv 2.1.35 → 2.1.37

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/index.js +64 -64
  3. package/package.json +6 -4
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-03T12:13:31Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/index.js CHANGED
@@ -1,73 +1,73 @@
1
1
  const OBJP = Object.getPrototypeOf({});
2
2
  const FN = "function";
3
3
  const STR = "string";
4
- export const equiv = (a, b) => {
5
- let proto;
6
- if (a === b) {
7
- return true;
8
- }
9
- if (a != null) {
10
- if (typeof a.equiv === FN) {
11
- return a.equiv(b);
12
- }
13
- }
14
- else {
15
- return a == b;
16
- }
17
- if (b != null) {
18
- if (typeof b.equiv === FN) {
19
- return b.equiv(a);
20
- }
21
- }
22
- else {
23
- return a == b;
24
- }
25
- if (typeof a === STR || typeof b === STR) {
26
- return false;
27
- }
28
- if (((proto = Object.getPrototypeOf(a)), proto == null || proto === OBJP) &&
29
- ((proto = Object.getPrototypeOf(b)), proto == null || proto === OBJP)) {
30
- return equivObject(a, b);
31
- }
32
- if (typeof a !== FN &&
33
- a.length !== undefined &&
34
- typeof b !== FN &&
35
- b.length !== undefined) {
36
- return equivArrayLike(a, b);
37
- }
38
- if (a instanceof Set && b instanceof Set) {
39
- return equivSet(a, b);
40
- }
41
- if (a instanceof Map && b instanceof Map) {
42
- return equivMap(a, b);
43
- }
44
- if (a instanceof Date && b instanceof Date) {
45
- return a.getTime() === b.getTime();
4
+ const equiv = (a, b) => {
5
+ let proto;
6
+ if (a === b) {
7
+ return true;
8
+ }
9
+ if (a != null) {
10
+ if (typeof a.equiv === FN) {
11
+ return a.equiv(b);
46
12
  }
47
- if (a instanceof RegExp && b instanceof RegExp) {
48
- return a.toString() === b.toString();
13
+ } else {
14
+ return a == b;
15
+ }
16
+ if (b != null) {
17
+ if (typeof b.equiv === FN) {
18
+ return b.equiv(a);
49
19
  }
50
- // NaN
51
- return a !== a && b !== b;
20
+ } else {
21
+ return a == b;
22
+ }
23
+ if (typeof a === STR || typeof b === STR) {
24
+ return false;
25
+ }
26
+ if ((proto = Object.getPrototypeOf(a), proto == null || proto === OBJP) && (proto = Object.getPrototypeOf(b), proto == null || proto === OBJP)) {
27
+ return equivObject(a, b);
28
+ }
29
+ if (typeof a !== FN && a.length !== void 0 && typeof b !== FN && b.length !== void 0) {
30
+ return equivArrayLike(a, b);
31
+ }
32
+ if (a instanceof Set && b instanceof Set) {
33
+ return equivSet(a, b);
34
+ }
35
+ if (a instanceof Map && b instanceof Map) {
36
+ return equivMap(a, b);
37
+ }
38
+ if (a instanceof Date && b instanceof Date) {
39
+ return a.getTime() === b.getTime();
40
+ }
41
+ if (a instanceof RegExp && b instanceof RegExp) {
42
+ return a.toString() === b.toString();
43
+ }
44
+ return a !== a && b !== b;
52
45
  };
53
- export const equivArrayLike = (a, b, _equiv = equiv) => {
54
- let l = a.length;
55
- if (l === b.length) {
56
- while (l-- > 0 && _equiv(a[l], b[l]))
57
- ;
58
- }
59
- return l < 0;
46
+ const equivArrayLike = (a, b, _equiv = equiv) => {
47
+ let l = a.length;
48
+ if (l === b.length) {
49
+ while (l-- > 0 && _equiv(a[l], b[l]))
50
+ ;
51
+ }
52
+ return l < 0;
60
53
  };
61
- export const equivSet = (a, b, _equiv = equiv) => a.size === b.size && _equiv([...a.keys()].sort(), [...b.keys()].sort());
62
- export const equivMap = (a, b, _equiv = equiv) => a.size === b.size && _equiv([...a].sort(), [...b].sort());
63
- export const equivObject = (a, b, _equiv = equiv) => {
64
- if (Object.keys(a).length !== Object.keys(b).length) {
65
- return false;
54
+ const equivSet = (a, b, _equiv = equiv) => a.size === b.size && _equiv([...a.keys()].sort(), [...b.keys()].sort());
55
+ const equivMap = (a, b, _equiv = equiv) => a.size === b.size && _equiv([...a].sort(), [...b].sort());
56
+ const equivObject = (a, b, _equiv = equiv) => {
57
+ if (Object.keys(a).length !== Object.keys(b).length) {
58
+ return false;
59
+ }
60
+ for (let k in a) {
61
+ if (!b.hasOwnProperty(k) || !_equiv(a[k], b[k])) {
62
+ return false;
66
63
  }
67
- for (let k in a) {
68
- if (!b.hasOwnProperty(k) || !_equiv(a[k], b[k])) {
69
- return false;
70
- }
71
- }
72
- return true;
64
+ }
65
+ return true;
66
+ };
67
+ export {
68
+ equiv,
69
+ equivArrayLike,
70
+ equivMap,
71
+ equivObject,
72
+ equivSet
73
73
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/equiv",
3
- "version": "2.1.35",
3
+ "version": "2.1.37",
4
4
  "description": "Extensible deep value equivalence checking for any data types",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -24,7 +24,9 @@
24
24
  "author": "Karsten Schmidt (https://thi.ng)",
25
25
  "license": "Apache-2.0",
26
26
  "scripts": {
27
- "build": "yarn clean && tsc --declaration",
27
+ "build": "yarn build:esbuild && yarn build:decl",
28
+ "build:decl": "tsc --declaration --emitDeclarationOnly",
29
+ "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
28
30
  "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
29
31
  "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
30
32
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
@@ -34,7 +36,7 @@
34
36
  },
35
37
  "devDependencies": {
36
38
  "@microsoft/api-extractor": "^7.38.3",
37
- "@thi.ng/testament": "^0.4.3",
39
+ "esbuild": "^0.19.8",
38
40
  "rimraf": "^5.0.5",
39
41
  "tools": "^0.0.1",
40
42
  "typedoc": "^0.25.4",
@@ -67,5 +69,5 @@
67
69
  "default": "./index.js"
68
70
  }
69
71
  },
70
- "gitHead": "04d1de79f256d7a53c6b5fd157b37f49bc88e11d\n"
72
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
71
73
  }