@magic/types 0.1.27 → 0.1.29
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 +17 -1
- package/package.json +4 -4
- package/src/deep/equal.js +12 -4
- package/src/lib.js +62 -35
- package/types/index.d.ts +4 -4
- package/types/lib.d.ts +24 -4
package/README.md
CHANGED
|
@@ -176,6 +176,12 @@ isDeepEqual([1, 2, 3], [1, 2, 3]) // true
|
|
|
176
176
|
isDeepDifferent([1, 2, 3], [1, 2, 3]) // false
|
|
177
177
|
// alias is.deep.diff, is.deep.different
|
|
178
178
|
|
|
179
|
+
isDeepEqual([1, 2, 3], [3, 2, 1]) // true
|
|
180
|
+
isDeepEqual([1, 2, 3], [3, 2, 1], { strict: true }) // false
|
|
181
|
+
|
|
182
|
+
isDeepEqual({a: 1, b: 2, c: 3 }, { c: 3, b: 2, a: 1 }) // true
|
|
183
|
+
isDeepEqual({a: 1, b: 2, c: 3 }, { c: 3, b: 2, a: 1 }, { strict: true }) // false
|
|
184
|
+
|
|
179
185
|
isEvery([1, 2, 3], 'number') // true
|
|
180
186
|
isEvery([1, 2, 3], is.number) // true
|
|
181
187
|
// alias is.every, is.all
|
|
@@ -210,6 +216,7 @@ isModule(mod) // true
|
|
|
210
216
|
|
|
211
217
|
isOwnProp({ test: undefined }, 'test') // true
|
|
212
218
|
// alias isOwnProperty, is.ownProperty, is.ownProp, is.prop
|
|
219
|
+
|
|
213
220
|
```
|
|
214
221
|
|
|
215
222
|
#### Changelog
|
|
@@ -348,6 +355,15 @@ update dependencies
|
|
|
348
355
|
- @types/node is a dependency, not devDependency
|
|
349
356
|
- update dependencies
|
|
350
357
|
|
|
351
|
-
##### 0.1.28
|
|
358
|
+
##### 0.1.28
|
|
359
|
+
|
|
360
|
+
- options.strict makes the tests include sort order of objects and array, [1, 2] is [2, 1] if options.strict = true
|
|
361
|
+
- update dependencies
|
|
362
|
+
|
|
363
|
+
##### 0.1.29
|
|
364
|
+
|
|
365
|
+
- change types of is.ln, is.len, is.length and is.count to reflect their type as function with subfunctions
|
|
366
|
+
|
|
367
|
+
##### 0.1.30 - unreleased
|
|
352
368
|
|
|
353
369
|
...
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magic/types",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"author": "Wizards & Witches",
|
|
5
5
|
"homepage": "https://github.com/magic/types",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"scripts": {
|
|
12
12
|
"start": "t",
|
|
13
|
-
"build": "tsc && npm run format
|
|
14
|
-
"prepublishOnly": "npm run build",
|
|
13
|
+
"build": "tsc && npm run format",
|
|
14
|
+
"prepublishOnly": "npm run test && npm run build",
|
|
15
15
|
"build:docs": "NODE_ENV=production magic build",
|
|
16
16
|
"prod": "NODE_ENV=production magic build serve",
|
|
17
17
|
"clean": "magic clean",
|
|
@@ -61,6 +61,6 @@
|
|
|
61
61
|
}
|
|
62
62
|
],
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@types/node": "24.
|
|
64
|
+
"@types/node": "24.7.1"
|
|
65
65
|
}
|
|
66
66
|
}
|
package/src/deep/equal.js
CHANGED
|
@@ -16,9 +16,11 @@ import is from '../lib.js'
|
|
|
16
16
|
/**
|
|
17
17
|
* @param {unknown} a
|
|
18
18
|
* @param {unknown} [b]
|
|
19
|
+
* @param {object} [options]
|
|
20
|
+
* @param {boolean} [options.strict=false]
|
|
19
21
|
* @returns {boolean | ((c: unknown) => boolean)}
|
|
20
22
|
*/
|
|
21
|
-
export const equal = (a, b) => {
|
|
23
|
+
export const equal = (a, b, options = { strict: false }) => {
|
|
22
24
|
// curry
|
|
23
25
|
if (is.undefined(b)) {
|
|
24
26
|
if (is.undefined(a)) {
|
|
@@ -46,7 +48,6 @@ export const equal = (a, b) => {
|
|
|
46
48
|
// return is.length.eq(a, b)
|
|
47
49
|
// }
|
|
48
50
|
|
|
49
|
-
// Check if both are objects before accessing prototype
|
|
50
51
|
if (!is.object(a) || !is.object(b)) {
|
|
51
52
|
return a === b
|
|
52
53
|
}
|
|
@@ -100,6 +101,11 @@ export const equal = (a, b) => {
|
|
|
100
101
|
return false
|
|
101
102
|
}
|
|
102
103
|
|
|
104
|
+
if (!options.strict) {
|
|
105
|
+
a.sort()
|
|
106
|
+
b.sort()
|
|
107
|
+
}
|
|
108
|
+
|
|
103
109
|
return !a.some((v, i) => v !== b[i])
|
|
104
110
|
}
|
|
105
111
|
|
|
@@ -118,8 +124,10 @@ export const equal = (a, b) => {
|
|
|
118
124
|
return false
|
|
119
125
|
}
|
|
120
126
|
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
if (!options.strict) {
|
|
128
|
+
ka.sort()
|
|
129
|
+
kb.sort()
|
|
130
|
+
}
|
|
123
131
|
|
|
124
132
|
// ~~~cheap key test
|
|
125
133
|
for (let i = 0; i < ka.length; i++) {
|
package/src/lib.js
CHANGED
|
@@ -1,11 +1,68 @@
|
|
|
1
1
|
import * as fns from './fns.js'
|
|
2
2
|
import * as deep from './deep/index.js'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
// count, length, len and ln are functions that return the length,
|
|
5
|
+
// but they also have comparison methods attached as properties.
|
|
6
|
+
// This creates enhanced length functions with comparison capabilities.
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {typeof fns.isLengthEqual} LengthComparison
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {typeof fns.getLength & {
|
|
14
|
+
* eq: LengthComparison,
|
|
15
|
+
* equal: LengthComparison,
|
|
16
|
+
* gt: LengthComparison,
|
|
17
|
+
* bigger: LengthComparison,
|
|
18
|
+
* biggerequal: LengthComparison,
|
|
19
|
+
* greater: LengthComparison,
|
|
20
|
+
* greaterequal: LengthComparison,
|
|
21
|
+
* gte: LengthComparison,
|
|
22
|
+
* gteq: LengthComparison,
|
|
23
|
+
* lower: LengthComparison,
|
|
24
|
+
* smaller: LengthComparison,
|
|
25
|
+
* lt: LengthComparison,
|
|
26
|
+
* lowerequal: LengthComparison,
|
|
27
|
+
* smallerequal: LengthComparison,
|
|
28
|
+
* lte: LengthComparison,
|
|
29
|
+
* lteq: LengthComparison
|
|
30
|
+
* }} EnhancedLengthFunction
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
// Create enhanced length functions with comparison methods
|
|
34
|
+
const lengthFunctions = {
|
|
35
|
+
eq: fns.isLengthEqual,
|
|
36
|
+
equal: fns.isLengthEqual,
|
|
37
|
+
gt: fns.isLengthGreater,
|
|
38
|
+
bigger: fns.isLengthGreater,
|
|
39
|
+
biggerequal: fns.isLengthGreaterOrEqual,
|
|
40
|
+
greater: fns.isLengthGreater,
|
|
41
|
+
greaterequal: fns.isLengthGreaterOrEqual,
|
|
42
|
+
gte: fns.isLengthGreaterOrEqual,
|
|
43
|
+
gteq: fns.isLengthGreaterOrEqual,
|
|
44
|
+
lower: fns.isLengthSmaller,
|
|
45
|
+
smaller: fns.isLengthSmaller,
|
|
46
|
+
lt: fns.isLengthSmaller,
|
|
47
|
+
lowerequal: fns.isLengthSmallerOrEqual,
|
|
48
|
+
smallerequal: fns.isLengthSmallerOrEqual,
|
|
49
|
+
lte: fns.isLengthSmallerOrEqual,
|
|
50
|
+
lteq: fns.isLengthSmallerOrEqual,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Replace the original length functions with enhanced versions
|
|
54
|
+
const ln = /** @type {EnhancedLengthFunction} */ (fns.getLength)
|
|
55
|
+
Object.assign(ln, lengthFunctions)
|
|
56
|
+
|
|
57
|
+
const length = ln
|
|
58
|
+
const len = ln
|
|
59
|
+
const count = ln
|
|
60
|
+
|
|
61
|
+
export const is = /** @type {const} */ {
|
|
62
|
+
count,
|
|
63
|
+
length,
|
|
64
|
+
len,
|
|
65
|
+
ln,
|
|
9
66
|
|
|
10
67
|
isError: fns.isError,
|
|
11
68
|
error: fns.isError,
|
|
@@ -269,34 +326,4 @@ export const is = {
|
|
|
269
326
|
...deep,
|
|
270
327
|
}
|
|
271
328
|
|
|
272
|
-
// count, length, len and ln are functions that return the length,
|
|
273
|
-
// but they also have comparison methods attached as properties.
|
|
274
|
-
// This creates enhanced length functions with comparison capabilities.
|
|
275
|
-
|
|
276
|
-
// Create enhanced length functions with comparison methods
|
|
277
|
-
const lengthFunctions = {
|
|
278
|
-
eq: fns.isLengthEqual,
|
|
279
|
-
equal: fns.isLengthEqual,
|
|
280
|
-
gt: fns.isLengthGreater,
|
|
281
|
-
bigger: fns.isLengthGreater,
|
|
282
|
-
biggerequal: fns.isLengthGreaterOrEqual,
|
|
283
|
-
greater: fns.isLengthGreater,
|
|
284
|
-
greaterequal: fns.isLengthGreaterOrEqual,
|
|
285
|
-
gte: fns.isLengthGreaterOrEqual,
|
|
286
|
-
gteq: fns.isLengthGreaterOrEqual,
|
|
287
|
-
lower: fns.isLengthSmaller,
|
|
288
|
-
smaller: fns.isLengthSmaller,
|
|
289
|
-
lt: fns.isLengthSmaller,
|
|
290
|
-
lowerequal: fns.isLengthSmallerOrEqual,
|
|
291
|
-
smallerequal: fns.isLengthSmallerOrEqual,
|
|
292
|
-
lte: fns.isLengthSmallerOrEqual,
|
|
293
|
-
lteq: fns.isLengthSmallerOrEqual,
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// Replace the original length functions with enhanced versions
|
|
297
|
-
is.ln = fns.getLength
|
|
298
|
-
Object.assign(is.ln, lengthFunctions)
|
|
299
|
-
|
|
300
|
-
is.length = is.len = is.count = is.ln
|
|
301
|
-
|
|
302
329
|
export default is
|
package/types/index.d.ts
CHANGED
|
@@ -183,10 +183,10 @@ export const is: {
|
|
|
183
183
|
(a: unknown): (c: unknown) => boolean
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
count: (
|
|
187
|
-
length: (
|
|
188
|
-
len: (
|
|
189
|
-
ln: (
|
|
186
|
+
count: import('./lib.js').EnhancedLengthFunction
|
|
187
|
+
length: import('./lib.js').EnhancedLengthFunction
|
|
188
|
+
len: import('./lib.js').EnhancedLengthFunction
|
|
189
|
+
ln: import('./lib.js').EnhancedLengthFunction
|
|
190
190
|
isError: (e: unknown) => e is Error
|
|
191
191
|
error: (e: unknown) => e is Error
|
|
192
192
|
err: (e: unknown) => e is Error
|
package/types/lib.d.ts
CHANGED
|
@@ -181,10 +181,10 @@ export const is: {
|
|
|
181
181
|
(a: unknown): (c: unknown) => boolean
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
|
-
count:
|
|
185
|
-
length:
|
|
186
|
-
len:
|
|
187
|
-
ln:
|
|
184
|
+
count: EnhancedLengthFunction
|
|
185
|
+
length: EnhancedLengthFunction
|
|
186
|
+
len: EnhancedLengthFunction
|
|
187
|
+
ln: EnhancedLengthFunction
|
|
188
188
|
isError: (e: unknown) => e is Error
|
|
189
189
|
error: (e: unknown) => e is Error
|
|
190
190
|
err: (e: unknown) => e is Error
|
|
@@ -508,3 +508,23 @@ export const is: {
|
|
|
508
508
|
}
|
|
509
509
|
}
|
|
510
510
|
export default is
|
|
511
|
+
export type LengthComparison = typeof fns.isLengthEqual
|
|
512
|
+
export type EnhancedLengthFunction = typeof fns.getLength & {
|
|
513
|
+
eq: LengthComparison
|
|
514
|
+
equal: LengthComparison
|
|
515
|
+
gt: LengthComparison
|
|
516
|
+
bigger: LengthComparison
|
|
517
|
+
biggerequal: LengthComparison
|
|
518
|
+
greater: LengthComparison
|
|
519
|
+
greaterequal: LengthComparison
|
|
520
|
+
gte: LengthComparison
|
|
521
|
+
gteq: LengthComparison
|
|
522
|
+
lower: LengthComparison
|
|
523
|
+
smaller: LengthComparison
|
|
524
|
+
lt: LengthComparison
|
|
525
|
+
lowerequal: LengthComparison
|
|
526
|
+
smallerequal: LengthComparison
|
|
527
|
+
lte: LengthComparison
|
|
528
|
+
lteq: LengthComparison
|
|
529
|
+
}
|
|
530
|
+
import * as fns from './fns.js'
|