@magic/types 0.1.22 → 0.1.25

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
@@ -23,11 +23,13 @@ typechecking utilities
23
23
  [snyk-url]: https://snyk.io/test/github/magic/types
24
24
 
25
25
  ##### install
26
+
26
27
  ```javascript
27
28
  npm install @magic/types
28
29
  ```
29
30
 
30
31
  ##### import single function
32
+
31
33
  ```js
32
34
  // single function import
33
35
  import { isArray } from '@magic/types'
@@ -36,6 +38,7 @@ isArray([]) // true
36
38
  ```
37
39
 
38
40
  ##### import all functions
41
+
39
42
  ```javascript
40
43
  import is from '@magic/types'
41
44
 
@@ -43,6 +46,7 @@ is.array([]) // true
43
46
  ```
44
47
 
45
48
  ##### functions
49
+
46
50
  ```javascript
47
51
 
48
52
  // comparisons
@@ -208,93 +212,133 @@ isOwnProp({ test: undefined }, 'test') // true
208
212
  // alias isOwnProperty, is.ownProperty, is.ownProp, is.prop
209
213
  ```
210
214
 
211
-
212
215
  #### Changelog
213
216
 
214
217
  ##### 0.0.5
218
+
215
219
  added Map, WeakMap, Set and WeakSet
216
220
 
217
221
  ##### 0.1.0
222
+
218
223
  use es6 modules
219
224
 
220
225
  ##### 0.1.1
226
+
221
227
  FIX: add module field to package.json
222
228
 
223
229
  ##### 0.1.2
230
+
224
231
  FIX: is.number no longer errors on node es6 modules and other weird objects
225
232
 
226
233
  ##### 0.1.3
234
+
227
235
  use @magic/deep for is.deep.equal and is.deep.different
228
236
 
229
237
  ##### 0.1.4
238
+
230
239
  is.deep uses @magic/deep now.
231
240
 
232
241
  this means that is.deep.equal(null, undefined) is returning a function now,
233
242
  because it expects currying.
234
243
 
235
244
  ##### 0.1.5
245
+
236
246
  minimum node version is 13.5.0
237
247
 
238
248
  ##### 0.1.6
249
+
239
250
  remove @magic/deep dependency
240
251
 
241
252
  ##### 0.1.7
253
+
242
254
  fix erroneous '@magic/types' import in src/deep/equal.mjs
243
255
 
244
256
  ##### 0.1.8
257
+
245
258
  add
246
- * is.every
247
- * is.some
248
- * is.none
259
+
260
+ - is.every
261
+ - is.some
262
+ - is.none
249
263
 
250
264
  ##### 0.1.9
265
+
251
266
  add is.instanceOf
252
267
 
253
268
  ##### 0.1.10
269
+
254
270
  add isCase, isUpperCase, isLowerCase
255
271
 
256
272
  ##### 0.1.11
273
+
257
274
  add isObjectNative
258
275
 
259
276
  ##### 0.1.12
277
+
260
278
  bump required node version to 14.2.0
261
279
 
262
280
  ##### 0.1.13
263
- * add isAsyncFunction
264
- * add isGeneratorFunction
281
+
282
+ - add isAsyncFunction
283
+ - add isGeneratorFunction
265
284
 
266
285
  ##### 0.1.14
267
- * bump required node version to 14.15.4
268
- * update dependencies
286
+
287
+ - bump required node version to 14.15.4
288
+ - update dependencies
269
289
 
270
290
  ##### 0.1.15
291
+
271
292
  deep.equal now does return true for objects that have undefined property values
272
293
 
273
294
  ##### 0.1.16
274
- * remove circular dependencies
295
+
296
+ - remove circular dependencies
275
297
 
276
298
  ##### 0.1.17
277
- * add isSameType, isSame, same, sameType
278
- * update dev dependencies
299
+
300
+ - add isSameType, isSame, same, sameType
301
+ - update dev dependencies
279
302
 
280
303
  ##### 0.1.18
281
- * add isModule and isOwnProperty
282
- * update dependencies
304
+
305
+ - add isModule and isOwnProperty
306
+ - update dependencies
283
307
 
284
308
  ##### 0.1.19
309
+
285
310
  update dependencies
286
311
 
287
312
  ##### 0.1.20
313
+
288
314
  update dependencies
289
315
 
290
316
  ##### 0.1.21
291
- * isBuffer uses Buffer.isBuffer.
292
- * update dependencies
293
- * getLength does not use .length or .size property for unknown types. instead we test for is.array, is.string, is.map etc.
317
+
318
+ - isBuffer uses Buffer.isBuffer.
319
+ - update dependencies
320
+ - getLength does not use .length or .size property for unknown types. instead we test for is.array, is.string, is.map etc.
294
321
 
295
322
  ##### 0.1.22
296
- * update getLength to correctly return the length of buffers (regressed in 0.1.21).
297
- * add a test case for buffer length
298
323
 
299
- ##### 0.1.23 - unreleased
324
+ - update getLength to correctly return the length of buffers (regressed in 0.1.21).
325
+ - add a test case for buffer length
326
+
327
+ ##### 0.1.23
328
+
329
+ - update dev dependencies
330
+ - update docs
331
+
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 - unreleased
343
+
300
344
  ...
package/package.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "@magic/types",
3
- "version": "0.1.22",
3
+ "version": "0.1.25",
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 && node scripts/strip-js-extension.js && 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,7 +23,7 @@
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": {
@@ -31,17 +34,21 @@
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.7",
40
- "@magic-modules/pre": "0.0.11",
41
- "@magic-themes/docs": "0.0.14",
42
- "@magic/core": "0.0.141",
43
- "@magic/format": "0.0.40",
44
- "@magic/test": "0.2.11"
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