@magic/types 0.1.23 → 0.1.26

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
@@ -329,6 +329,20 @@ update dependencies
329
329
  - update dev dependencies
330
330
  - update docs
331
331
 
332
- ##### 0.1.24 - unreleased
332
+ ##### 0.1.24
333
+
334
+ - update dependencies
335
+
336
+ ##### 0.1.25
337
+
338
+ - add typescript types
339
+ - coverage is 100%
340
+ - update dependencies
341
+
342
+ ##### 0.1.26
343
+
344
+ - fix typescript d.ts files
345
+
346
+ ##### 0.0.27 - unreleased
333
347
 
334
348
  ...
package/package.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "@magic/types",
3
- "version": "0.1.23",
3
+ "version": "0.1.26",
4
4
  "author": "Wizards & Witches",
5
5
  "homepage": "https://github.com/magic/types",
6
6
  "license": "AGPL-3.0",
7
7
  "description": "typechecking library",
8
- "main": "src/index.mjs",
8
+ "main": "src/index.js",
9
+ "types": "./types/index.d.ts",
9
10
  "type": "module",
10
11
  "scripts": {
11
12
  "start": "t",
12
- "build": "NODE_ENV=production magic build",
13
+ "build": "tsc && npm run format && echo 'Types generated in dist/*'",
14
+ "prepublishOnly": "npm run build",
15
+ "build:docs": "NODE_ENV=production magic build",
13
16
  "prod": "NODE_ENV=production magic build serve",
14
17
  "clean": "magic clean",
15
18
  "serve": "magic serve",
@@ -20,28 +23,32 @@
20
23
  "calls": "calls"
21
24
  },
22
25
  "engines": {
23
- "node": ">=14.15.4"
26
+ "node": ">=18"
24
27
  },
25
28
  "engineStrict": true,
26
29
  "repository": {
27
30
  "type": "git",
28
- "url": "https://github.com/magic/types"
31
+ "url": "git+https://github.com/magic/types.git"
29
32
  },
30
33
  "bugs": {
31
34
  "url": "https://github.com/magic/types/issues"
32
35
  },
33
36
  "files": [
34
- "src"
37
+ "src",
38
+ "types"
35
39
  ],
36
40
  "devDependencies": {
37
41
  "@magic-modules/git-badges": "0.0.12",
38
- "@magic-modules/light-switch": "0.0.11",
39
- "@magic-modules/no-spy": "0.0.8",
40
- "@magic-modules/pre": "0.0.11",
41
- "@magic-themes/docs": "0.0.14",
42
- "@magic/core": "0.0.149",
43
- "@magic/format": "0.0.50",
44
- "@magic/test": "0.2.15"
42
+ "@magic-modules/light-switch": "0.0.12",
43
+ "@magic-modules/no-spy": "0.0.9",
44
+ "@magic-modules/pre": "0.0.12",
45
+ "@magic-themes/docs": "0.0.15",
46
+ "@magic/core": "0.0.156",
47
+ "@magic/format": "0.0.68",
48
+ "@magic/fs": "0.0.31",
49
+ "@magic/test": "0.2.20",
50
+ "@types/node": "24.5.2",
51
+ "typescript": "5.9.2"
45
52
  },
46
53
  "keywords": [
47
54
  "magic",
@@ -0,0 +1,33 @@
1
+ import is from '../lib.js'
2
+
3
+ import equal from './equal.js'
4
+
5
+ /**
6
+ * @overload
7
+ * @param {unknown} a
8
+ * @param {unknown} b
9
+ * @returns {boolean}
10
+ */
11
+ /**
12
+ * @overload
13
+ * @param {unknown} a
14
+ * @returns {(c: unknown) => boolean}
15
+ */
16
+ /**
17
+ * @param {unknown} a
18
+ * @param {unknown} [b]
19
+ * @returns {boolean | ((c: unknown) => boolean)}
20
+ */
21
+ export const different = (a, b) => {
22
+ if (is.undefined(b)) {
23
+ if (is.undefined(a)) {
24
+ return false
25
+ }
26
+
27
+ return c => different(a, c)
28
+ }
29
+
30
+ return !equal(a, b)
31
+ }
32
+
33
+ export default different
@@ -0,0 +1,146 @@
1
+ // Written by Substack <3
2
+
3
+ import is from '../lib.js'
4
+
5
+ /**
6
+ * @overload
7
+ * @param {unknown} a
8
+ * @param {unknown} b
9
+ * @returns {boolean}
10
+ */
11
+ /**
12
+ * @overload
13
+ * @param {unknown} a
14
+ * @returns {(c: unknown) => boolean}
15
+ */
16
+ /**
17
+ * @param {unknown} a
18
+ * @param {unknown} [b]
19
+ * @returns {boolean | ((c: unknown) => boolean)}
20
+ */
21
+ export const equal = (a, b) => {
22
+ // curry
23
+ if (is.undefined(b)) {
24
+ if (is.undefined(a)) {
25
+ return true
26
+ }
27
+
28
+ return c => equal(a, c)
29
+ }
30
+
31
+ if (is.null(b)) {
32
+ return a === b
33
+ }
34
+
35
+ // types must match
36
+ if (typeof a !== typeof b) {
37
+ return false
38
+ }
39
+
40
+ // bool, string, number, falsy values
41
+ if (is.comparable(a) || is.comparable(b)) {
42
+ return a === b
43
+ }
44
+
45
+ // if (is.arguments(a)) {
46
+ // return is.length.eq(a, b)
47
+ // }
48
+
49
+ // Check if both are objects before accessing prototype
50
+ if (!is.object(a) || !is.object(b)) {
51
+ return a === b
52
+ }
53
+
54
+ // identical 'prototype' property.
55
+ if ('prototype' in a && 'prototype' in b) {
56
+ return a.prototype === b.prototype
57
+ }
58
+
59
+ // real types must match too
60
+ // if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
61
+ // return false
62
+ // }
63
+
64
+ // dates
65
+ if (is.date(a)) {
66
+ return a === b
67
+ }
68
+
69
+ /* functions are handled by prototype comparison above */
70
+ // if (is.function(a)) {
71
+ // if (!is.function(b)) {
72
+ // return false
73
+ // }
74
+
75
+ // return a.toString() === b.toString()
76
+ // }
77
+
78
+ // buffers
79
+ if (is.buffer(a)) {
80
+ if (!is.buffer(b)) {
81
+ return false
82
+ }
83
+
84
+ if (a.length !== b.length) {
85
+ return false
86
+ }
87
+
88
+ for (let i = 0; i < a.length; i++) {
89
+ if (a[i] !== b[i]) {
90
+ return false
91
+ }
92
+ }
93
+
94
+ return true
95
+ }
96
+
97
+ if (is.objectNative(a) || is.array(a)) {
98
+ if (is.array(a)) {
99
+ if (!is.array(b)) {
100
+ return false
101
+ }
102
+
103
+ return !a.some((v, i) => v !== b[i])
104
+ }
105
+
106
+ if (!is.objectNative(b)) {
107
+ return false
108
+ }
109
+
110
+ const aObj = a
111
+ const bObj = b
112
+
113
+ const ka = Object.keys(aObj)
114
+ const kb = Object.keys(bObj)
115
+
116
+ // having the same number of owned properties (keys incorporates hasOwnProperty)
117
+ if (ka.length !== kb.length) {
118
+ return false
119
+ }
120
+
121
+ ka.sort()
122
+ kb.sort()
123
+
124
+ // ~~~cheap key test
125
+ for (let i = 0; i < ka.length; i++) {
126
+ if (ka[i] !== kb[i]) {
127
+ return false
128
+ }
129
+ }
130
+
131
+ // equivalent values for every corresponding key, and
132
+ // ~~~possibly expensive deep test
133
+ let key
134
+ for (let i = ka.length - 1; i >= 0; i--) {
135
+ key = ka[i]
136
+
137
+ if (!equal(aObj[key], bObj[key])) {
138
+ return false
139
+ }
140
+ }
141
+ }
142
+
143
+ return typeof a === typeof b
144
+ }
145
+
146
+ export default equal
@@ -1,5 +1,5 @@
1
- import { equal } from './equal.mjs'
2
- import { different } from './different.mjs'
1
+ import { equal } from './equal.js'
2
+ import { different } from './different.js'
3
3
 
4
4
  export const isDeepEqual = equal
5
5
  export const deepEqual = equal