@magic/types 0.1.16 → 0.1.17

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
 
@@ -260,5 +267,9 @@ deep.equal now does return true for objects that have undefined property values
260
267
  ##### 0.1.16
261
268
  * remove circular dependencies
262
269
 
263
- ##### 0.0.17 - unreleased
270
+ ##### 0.1.17
271
+ * add isSameType, isSame, same, sameType
272
+ * update dev dependencies
273
+
274
+ ##### 0.1.18 - unreleased
264
275
  ...
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic/types",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
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.133",
43
+ "@magic/format": "0.0.34",
44
+ "@magic/test": "0.2.0"
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 (arg !== undefined && arg.hasOwnProperty('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)
package/src/lib.mjs CHANGED
@@ -257,6 +257,11 @@ 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,
260
265
  }
261
266
 
262
267
  // assign ln as properties of the getLength function