@magic/types 0.1.29 → 0.1.30

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/README.md CHANGED
@@ -364,6 +364,11 @@ update dependencies
364
364
 
365
365
  - change types of is.ln, is.len, is.length and is.count to reflect their type as function with subfunctions
366
366
 
367
- ##### 0.1.30 - unreleased
367
+ ##### 0.1.30
368
+
369
+ - fix deep.equal and deep.different implementations and tests
370
+ - update dependencies
371
+
372
+ ##### 0.1.31 - unreleased
368
373
 
369
374
  ...
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic/types",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "author": "Wizards & Witches",
5
5
  "homepage": "https://github.com/magic/types",
6
6
  "license": "AGPL-3.0",
@@ -20,7 +20,8 @@
20
20
  "test": "t",
21
21
  "format": "f -w --exclude docs",
22
22
  "format:check": "f --exclude docs",
23
- "calls": "calls"
23
+ "calls": "calls",
24
+ "lint": "tsc --noEmit"
24
25
  },
25
26
  "engines": {
26
27
  "node": ">=18"
@@ -45,8 +46,7 @@
45
46
  "@magic-themes/docs": "0.0.15",
46
47
  "@magic/core": "0.0.156",
47
48
  "@magic/format": "0.0.68",
48
- "@magic/fs": "0.0.31",
49
- "@magic/test": "0.2.20",
49
+ "@magic/test": "0.2.24",
50
50
  "typescript": "5.9.3"
51
51
  },
52
52
  "keywords": [
@@ -61,6 +61,6 @@
61
61
  }
62
62
  ],
63
63
  "dependencies": {
64
- "@types/node": "24.7.1"
64
+ "@types/node": "24.9.2"
65
65
  }
66
66
  }
package/src/deep/equal.js CHANGED
@@ -18,9 +18,12 @@ import is from '../lib.js'
18
18
  * @param {unknown} [b]
19
19
  * @param {object} [options]
20
20
  * @param {boolean} [options.strict=false]
21
+ * @param {boolean} [options.arrayOrderStrict=true]
21
22
  * @returns {boolean | ((c: unknown) => boolean)}
22
23
  */
23
- export const equal = (a, b, options = { strict: false }) => {
24
+ export const equal = (a, b, options = {}) => {
25
+ const { strict = false, arrayOrderStrict = false } = options
26
+
24
27
  // curry
25
28
  if (is.undefined(b)) {
26
29
  if (is.undefined(a)) {
@@ -39,15 +42,11 @@ export const equal = (a, b, options = { strict: false }) => {
39
42
  return false
40
43
  }
41
44
 
42
- // bool, string, number, falsy values
43
- if (is.comparable(a) || is.comparable(b)) {
44
- return a === b
45
+ /* functions are handled by their toString value */
46
+ if (is.function(a) && is.function(b)) {
47
+ return a.toString() === b.toString()
45
48
  }
46
49
 
47
- // if (is.arguments(a)) {
48
- // return is.length.eq(a, b)
49
- // }
50
-
51
50
  if (!is.object(a) || !is.object(b)) {
52
51
  return a === b
53
52
  }
@@ -58,30 +57,17 @@ export const equal = (a, b, options = { strict: false }) => {
58
57
  }
59
58
 
60
59
  // real types must match too
61
- // if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
62
- // return false
63
- // }
60
+ if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
61
+ return false
62
+ }
64
63
 
65
64
  // dates
66
65
  if (is.date(a)) {
67
- return a === b
66
+ return a.toString() === b.toString()
68
67
  }
69
68
 
70
- /* functions are handled by prototype comparison above */
71
- // if (is.function(a)) {
72
- // if (!is.function(b)) {
73
- // return false
74
- // }
75
-
76
- // return a.toString() === b.toString()
77
- // }
78
-
79
69
  // buffers
80
- if (is.buffer(a)) {
81
- if (!is.buffer(b)) {
82
- return false
83
- }
84
-
70
+ if (is.buffer(a) && is.buffer(b)) {
85
71
  if (a.length !== b.length) {
86
72
  return false
87
73
  }
@@ -95,24 +81,17 @@ export const equal = (a, b, options = { strict: false }) => {
95
81
  return true
96
82
  }
97
83
 
98
- if (is.objectNative(a) || is.array(a)) {
99
- if (is.array(a)) {
100
- if (!is.array(b)) {
101
- return false
102
- }
103
-
104
- if (!options.strict) {
105
- a.sort()
106
- b.sort()
107
- }
108
-
109
- return !a.some((v, i) => v !== b[i])
84
+ if (is.array(a) && is.array(b)) {
85
+ if (!strict && !arrayOrderStrict) {
86
+ a.sort()
87
+ b.sort()
110
88
  }
111
89
 
112
- if (!is.objectNative(b)) {
113
- return false
114
- }
90
+ const allEqual = !a.some((v, i) => !equal(v, b[i]))
91
+ return allEqual
92
+ }
115
93
 
94
+ if (is.objectNative(a) && is.objectNative(b)) {
116
95
  const aObj = a
117
96
  const bObj = b
118
97
 
@@ -124,7 +103,7 @@ export const equal = (a, b, options = { strict: false }) => {
124
103
  return false
125
104
  }
126
105
 
127
- if (!options.strict) {
106
+ if (!strict) {
128
107
  ka.sort()
129
108
  kb.sort()
130
109
  }
@@ -137,15 +116,8 @@ export const equal = (a, b, options = { strict: false }) => {
137
116
  }
138
117
 
139
118
  // equivalent values for every corresponding key, and
140
- // ~~~possibly expensive deep test
141
- let key
142
- for (let i = ka.length - 1; i >= 0; i--) {
143
- key = ka[i]
144
-
145
- if (!equal(aObj[key], bObj[key])) {
146
- return false
147
- }
148
- }
119
+ // ~~~ possibly expensive deep test
120
+ return !ka.some(key => !equal(aObj[key], bObj[key]))
149
121
  }
150
122
 
151
123
  return typeof a === typeof b
package/src/fns.js CHANGED
@@ -340,7 +340,7 @@ export const isLengthSmallerOrEqual = (a, b) =>
340
340
  * - null/undefined → true
341
341
  * - arrays, objects, regex → empty if size < 1
342
342
  * - errors/dates → never empty
343
- * - numbers, strings → falsy or 0/""
343
+ * - numbers, strings → falsy or 0, ""
344
344
  * @param {unknown} e
345
345
  * @returns {boolean}
346
346
  */