@magic/types 0.1.16 → 0.1.19

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
@@ -45,6 +45,8 @@ is.array([]) // true
45
45
  ##### functions
46
46
  ```javascript
47
47
 
48
+ // comparisons
49
+
48
50
  // test a value for multiple types
49
51
  is(ele, ...types)
50
52
  // alias is.eq, isEq, test
@@ -53,7 +55,12 @@ is(ele, ...types)
53
55
  not(ele, ...types)
54
56
  // alias is.neq, isNeq, isNot
55
57
 
56
- type comparisons:
58
+ isSameType('string', 'string')
59
+ // alias isSame, is.same, is.sameType
60
+
61
+
62
+ // type comparisons:
63
+
57
64
  isArray([]) // true
58
65
  // alias isArr, is.array, is.arr
59
66
 
@@ -193,6 +200,12 @@ isLowerCase('lowercase') // true
193
200
  isMergeableObject({}) // true
194
201
  // alias is.mergeable, is.mergeableObject, isMergeable
195
202
 
203
+ const mod = await import('path/to/file')
204
+ isModule(mod) // true
205
+ // alias is.module
206
+
207
+ isOwnProp({ test: undefined }, 'test') // true
208
+ // alias isOwnProperty, is.ownProperty, is.ownProp, is.prop
196
209
  ```
197
210
 
198
211
 
@@ -260,5 +273,16 @@ deep.equal now does return true for objects that have undefined property values
260
273
  ##### 0.1.16
261
274
  * remove circular dependencies
262
275
 
263
- ##### 0.0.17 - unreleased
276
+ ##### 0.1.17
277
+ * add isSameType, isSame, same, sameType
278
+ * update dev dependencies
279
+
280
+ ##### 0.1.18
281
+ * add isModule and isOwnProperty
282
+ * update dependencies
283
+
284
+ ##### 0.1.19
285
+ update dependencies
286
+
287
+ ##### 0.1.20 - unreleased
264
288
  ...
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic/types",
3
- "version": "0.1.16",
3
+ "version": "0.1.19",
4
4
  "author": "Wizards & Witches",
5
5
  "homepage": "https://github.com/magic/types",
6
6
  "license": "AGPL-3.0",
@@ -37,11 +37,11 @@
37
37
  "@magic-modules/git-badges": "0.0.11",
38
38
  "@magic-modules/light-switch": "0.0.10",
39
39
  "@magic-modules/no-spy": "0.0.6",
40
- "@magic-modules/pre": "0.0.10",
41
- "@magic-themes/docs": "0.0.13",
42
- "@magic/core": "0.0.119",
43
- "@magic/format": "0.0.22",
44
- "@magic/test": "0.1.66"
40
+ "@magic-modules/pre": "0.0.11",
41
+ "@magic-themes/docs": "0.0.14",
42
+ "@magic/core": "0.0.139",
43
+ "@magic/format": "0.0.38",
44
+ "@magic/test": "0.2.8"
45
45
  },
46
46
  "keywords": [
47
47
  "magic",
package/src/fns.mjs CHANGED
@@ -79,12 +79,14 @@ export const isEmpty = e => {
79
79
  }
80
80
 
81
81
  export const getLength = arg => {
82
- if (isNumber(arg)) {
82
+ if (isOwnProp(arg, 'length') && isNumber(arg.length)) {
83
+ return arg.length
84
+ } else if (isNumber(arg)) {
83
85
  return arg
84
- } else if (isNumber(arg.length)) {
86
+ } else if (arg && isNumber(arg.length)) {
85
87
  // arrays, strings
86
88
  return arg.length
87
- } else if (isNumber(arg.size)) {
89
+ } else if (arg && isNumber(arg.size)) {
88
90
  // Set, Map, WeakMap etc
89
91
  return arg.size
90
92
  } else if (isRegExp(arg)) {
@@ -94,10 +96,12 @@ export const getLength = arg => {
94
96
  } else {
95
97
  return str.length > 2
96
98
  }
99
+ } else if (isObjectNative(arg)) {
100
+ return Object.keys(arg).length
97
101
  }
98
102
 
99
- // objects
100
- return Object.keys(arg).length
103
+ // unknown things
104
+ return -1
101
105
  }
102
106
 
103
107
  export const compareCount = (len, e) => getLength(len) === getLength(e)
@@ -121,7 +125,7 @@ export const isEmail = e => isString(e) && e.indexOf('@') > -1
121
125
 
122
126
  export const isNull = e => e === null
123
127
 
124
- export const isUndefinedOrNull = e => e === null || !isDefined(e)
128
+ export const isUndefinedOrNull = e => isNull(e) || !isDefined(e)
125
129
 
126
130
  export const isBuffer = e => {
127
131
  if (!e) {
@@ -181,6 +185,8 @@ export const isNot = (e, ...types) => !isTypes(e, ...types)
181
185
 
182
186
  export const isComparable = a => isBoolean(a) || isString(a) || isNumber(a)
183
187
 
188
+ export const isSameType = (a, b) => typeof a === typeof b
189
+
184
190
  const isElementCheck = (e, t) => (isFunction(t) ? t(e) : typeof e === t)
185
191
 
186
192
  export const isEvery = (arr, t) =>
@@ -191,7 +197,7 @@ export const isSome = (arr, t) =>
191
197
 
192
198
  export const isNone = (arr, t) => !isSome(arr, t)
193
199
 
194
- export const isInstanceOf = (e, t) => e instanceof t
200
+ export const isInstanceOf = (e, t) => (!t ? false : e instanceof t)
195
201
 
196
202
  export const isError = e => isInstanceOf(e, Error)
197
203
  export const isDate = e => isInstanceOf(e, Date)
@@ -204,7 +210,13 @@ export const isWeakSet = a => isInstanceOf(a, WeakSet)
204
210
  export const isUpperCase = s => (isString(s) ? s === s.toUpperCase() : false)
205
211
  export const isLowerCase = s => (isString(s) ? s === s.toLowerCase() : false)
206
212
 
207
- export const isCase = (s, c = 'up') => (c === 'up' ? isUpperCase(s) : isLowerCase(s))
213
+ export const isOwnProp = (o, k) =>
214
+ isDefined(o) && isFunction(o.hasOwnProperty) && o.hasOwnProperty(k)
208
215
 
216
+ export const isOwnProperty = isOwnProp
217
+
218
+ export const isModule = s => Object.prototype.toString.call(s) === '[object Module]'
219
+
220
+ export const isCase = (s, c = 'up') => (c === 'up' ? isUpperCase(s) : isLowerCase(s))
209
221
  isCase.upper = isUpperCase
210
222
  isCase.lower = isLowerCase
package/src/lib.mjs CHANGED
@@ -257,6 +257,20 @@ export const is = {
257
257
  upperCase: fns.isUpperCase,
258
258
  isLowerCase: fns.isLowerCase,
259
259
  lowerCase: fns.isLowerCase,
260
+
261
+ same: fns.isSameType,
262
+ sameType: fns.isSameType,
263
+ isSameType: fns.isSameType,
264
+ isSame: fns.isSameType,
265
+
266
+ ownProp: fns.isOwnProp,
267
+ prop: fns.isOwnProp,
268
+ ownProperty: fns.isOwnProp,
269
+ isOwnProp: fns.isOwnProp,
270
+ isOwnProperty: fns.isOwnProp,
271
+
272
+ isModule: fns.isModule,
273
+ module: fns.isModule,
260
274
  }
261
275
 
262
276
  // assign ln as properties of the getLength function