@magic/types 0.1.14 → 0.1.18
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 +32 -2
- package/package.json +7 -6
- package/src/deep/different.mjs +1 -1
- package/src/deep/equal.mjs +8 -1
- package/src/deep/index.mjs +16 -3
- package/src/fns.mjs +222 -0
- package/src/index.mjs +5 -513
- package/src/lib.mjs +308 -0
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
|
-
|
|
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
|
|
|
@@ -190,6 +197,15 @@ isUpperCase('UPPERCASE') // true
|
|
|
190
197
|
isLowerCase('lowercase') // true
|
|
191
198
|
// alias is.case.lower, is.isCase.lower
|
|
192
199
|
|
|
200
|
+
isMergeableObject({}) // true
|
|
201
|
+
// alias is.mergeable, is.mergeableObject, isMergeable
|
|
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
|
|
193
209
|
```
|
|
194
210
|
|
|
195
211
|
|
|
@@ -251,5 +267,19 @@ bump required node version to 14.2.0
|
|
|
251
267
|
* bump required node version to 14.15.4
|
|
252
268
|
* update dependencies
|
|
253
269
|
|
|
254
|
-
##### 0.1.15
|
|
270
|
+
##### 0.1.15
|
|
271
|
+
deep.equal now does return true for objects that have undefined property values
|
|
272
|
+
|
|
273
|
+
##### 0.1.16
|
|
274
|
+
* remove circular dependencies
|
|
275
|
+
|
|
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 - unreleased
|
|
255
285
|
...
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magic/types",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
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
8
|
"main": "src/index.mjs",
|
|
9
|
+
"type": "module",
|
|
9
10
|
"scripts": {
|
|
10
11
|
"start": "t",
|
|
11
12
|
"build": "NODE_ENV=production magic build",
|
|
@@ -36,11 +37,11 @@
|
|
|
36
37
|
"@magic-modules/git-badges": "0.0.11",
|
|
37
38
|
"@magic-modules/light-switch": "0.0.10",
|
|
38
39
|
"@magic-modules/no-spy": "0.0.6",
|
|
39
|
-
"@magic-modules/pre": "0.0.
|
|
40
|
-
"@magic-themes/docs": "0.0.
|
|
41
|
-
"@magic/core": "0.0.
|
|
42
|
-
"@magic/format": "0.0.
|
|
43
|
-
"@magic/test": "0.
|
|
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.35",
|
|
44
|
+
"@magic/test": "0.2.0"
|
|
44
45
|
},
|
|
45
46
|
"keywords": [
|
|
46
47
|
"magic",
|
package/src/deep/different.mjs
CHANGED
package/src/deep/equal.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Written by Substack <3
|
|
2
2
|
|
|
3
|
-
import is from '../
|
|
3
|
+
import is from '../lib.mjs'
|
|
4
4
|
|
|
5
5
|
export const equal = (a, b) => {
|
|
6
6
|
// curry
|
|
@@ -90,6 +90,13 @@ export const equal = (a, b) => {
|
|
|
90
90
|
let key
|
|
91
91
|
for (let i = ka.length - 1; i >= 0; i--) {
|
|
92
92
|
key = ka[i]
|
|
93
|
+
|
|
94
|
+
// in the first line of this function we assume that two undefined values are a bug.
|
|
95
|
+
// here we have to assume that two undefined properties in an object are intentional.
|
|
96
|
+
if (is.undefined(a[key])) {
|
|
97
|
+
return a[key] === b[key]
|
|
98
|
+
}
|
|
99
|
+
|
|
93
100
|
if (!equal(a[key], b[key])) {
|
|
94
101
|
return false
|
|
95
102
|
}
|
package/src/deep/index.mjs
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import { equal } from './equal.mjs'
|
|
2
2
|
import { different } from './different.mjs'
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export const isDeepEqual = equal
|
|
5
|
+
export const deepEqual = equal
|
|
6
|
+
export const deepEq = equal
|
|
7
|
+
|
|
8
|
+
export const isDeepDifferent = different
|
|
9
|
+
export const deepDifferent = different
|
|
10
|
+
export const deepDiff = different
|
|
11
|
+
|
|
12
|
+
export const deep = {
|
|
13
|
+
isDifferent: different,
|
|
14
|
+
different: different,
|
|
15
|
+
diff: different,
|
|
16
|
+
|
|
17
|
+
isEqual: equal,
|
|
18
|
+
equal: equal,
|
|
19
|
+
eq: equal,
|
|
7
20
|
}
|
package/src/fns.mjs
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
export const isArray = e => Array.isArray(e)
|
|
2
|
+
|
|
3
|
+
export const isBoolean = e => typeof e === 'boolean'
|
|
4
|
+
|
|
5
|
+
export const isDefined = e => typeof e !== 'undefined'
|
|
6
|
+
|
|
7
|
+
export const isUndefined = e => !isDefined(e)
|
|
8
|
+
|
|
9
|
+
export const isFunction = e => typeof e === 'function'
|
|
10
|
+
|
|
11
|
+
export const isAsyncFunction = e => Object.prototype.toString.call(e) === '[object AsyncFunction]'
|
|
12
|
+
|
|
13
|
+
export const isGeneratorFunction = e =>
|
|
14
|
+
Object.prototype.toString.call(e) === '[object GeneratorFunction]'
|
|
15
|
+
|
|
16
|
+
export const isNumber = e => typeof e !== 'object' && e === +e
|
|
17
|
+
|
|
18
|
+
export const isInteger = e => e === +e && e === (e | 0)
|
|
19
|
+
|
|
20
|
+
export const isFloat = e => e === +e
|
|
21
|
+
|
|
22
|
+
export const isObject = e => typeof e === 'object' && !isNull(e)
|
|
23
|
+
|
|
24
|
+
export const isObjectNative = e => Object.prototype.toString.call(e) === '[object Object]'
|
|
25
|
+
|
|
26
|
+
export const isMergeableObject = e => isObject(e) && !isDate(e) && !isRegExp(e)
|
|
27
|
+
export const isMergeable = isMergeableObject
|
|
28
|
+
|
|
29
|
+
export const isString = e => typeof e === 'string'
|
|
30
|
+
|
|
31
|
+
export const isRGBValue = e => ![e.r, e.g, e.b].some(n => !isNumber(n))
|
|
32
|
+
export const isRGBAValue = e => ![e.r, e.g, e.b, e.a].some(n => !isNumber(n))
|
|
33
|
+
|
|
34
|
+
export const isRGBAObject = e => isObject(e) && isRGBAValue(e)
|
|
35
|
+
|
|
36
|
+
export const isRGBObject = e => isObject(e) && isRGBValue(e)
|
|
37
|
+
|
|
38
|
+
export const hexRegex = /#\b([a-f0-9]{3}|[a-f0-9]{4}|[a-f0-9]{6}|[a-f0-9]{8})\b/i
|
|
39
|
+
export const isHexColor = e => hexRegex.test(e)
|
|
40
|
+
|
|
41
|
+
export const isHexColor3 = e => /#\b([a-f0-9]{3})\b/i.test(e)
|
|
42
|
+
|
|
43
|
+
export const isHexColor4 = e => /#\b([a-f0-9]{4})\b/i.test(e)
|
|
44
|
+
|
|
45
|
+
export const isHexColor6 = e => /#\b([a-f0-9]{6})\b/i.test(e)
|
|
46
|
+
|
|
47
|
+
export const isHexColor8 = e => /#\b([a-f0-9]{8})\b/i.test(e)
|
|
48
|
+
|
|
49
|
+
export const isHexAlphaColor = e => /#\b([a-f0-9]{4}|[a-f0-9]{8})\b/i.test(e)
|
|
50
|
+
|
|
51
|
+
export const isHexAlphaColor4 = e => /#\b([a-f0-9]{4})\b/i.test(e)
|
|
52
|
+
|
|
53
|
+
export const isHexAlphaColor8 = e => /#\b([a-f0-9]{8})\b/i.test(e)
|
|
54
|
+
|
|
55
|
+
export const isColor = e => isRGBAObject(e) || isRGBObject(e) || isHexColor(e) || isHexAlphaColor(e)
|
|
56
|
+
|
|
57
|
+
export const isTruthy = e => !!e
|
|
58
|
+
|
|
59
|
+
export const isFalsy = e => !e || isEmpty(e)
|
|
60
|
+
|
|
61
|
+
export const isEmpty = e => {
|
|
62
|
+
if (isError(e)) {
|
|
63
|
+
return false
|
|
64
|
+
} else if (isDate(e)) {
|
|
65
|
+
return false
|
|
66
|
+
} else if (isNull(e)) {
|
|
67
|
+
return true
|
|
68
|
+
} else if (isUndefined(e)) {
|
|
69
|
+
return true
|
|
70
|
+
} else if (isArray(e)) {
|
|
71
|
+
return isLengthSmaller(e, 1)
|
|
72
|
+
} else if (isRegExp(e)) {
|
|
73
|
+
return isLengthSmaller(e, 1)
|
|
74
|
+
} else if (isObject(e)) {
|
|
75
|
+
return isLengthSmaller(e, 1)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return e === 0 || e === '' || !e
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const getLength = arg => {
|
|
82
|
+
if (isOwnProp(arg, 'length') && isNumber(arg.length)) {
|
|
83
|
+
return arg.length
|
|
84
|
+
} else if (isNumber(arg)) {
|
|
85
|
+
return arg
|
|
86
|
+
} else if (arg && isNumber(arg.length)) {
|
|
87
|
+
// arrays, strings
|
|
88
|
+
return arg.length
|
|
89
|
+
} else if (arg && isNumber(arg.size)) {
|
|
90
|
+
// Set, Map, WeakMap etc
|
|
91
|
+
return arg.size
|
|
92
|
+
} else if (isRegExp(arg)) {
|
|
93
|
+
const str = arg.toString()
|
|
94
|
+
if (str === '/(?:)/') {
|
|
95
|
+
return 0
|
|
96
|
+
} else {
|
|
97
|
+
return str.length > 2
|
|
98
|
+
}
|
|
99
|
+
} else if (isObjectNative(arg)) {
|
|
100
|
+
return Object.keys(arg).length
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// unknown things
|
|
104
|
+
return -1
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const compareCount = (len, e) => getLength(len) === getLength(e)
|
|
108
|
+
export const isLengthEqual = (a, b) => (isDefined(b) ? compareCount(a, b) : b => compareCount(a, b))
|
|
109
|
+
|
|
110
|
+
export const isLengthGreater = (a, b) =>
|
|
111
|
+
isDefined(b) ? getLength(a) > getLength(b) : c => isLengthGreater(a, c)
|
|
112
|
+
|
|
113
|
+
export const isLengthGreaterOrEqual = (a, b) =>
|
|
114
|
+
isDefined(b) ? getLength(a) >= getLength(b) : c => isLengthGreaterOrEqual(a, c)
|
|
115
|
+
|
|
116
|
+
export const isLengthSmaller = (a, b) =>
|
|
117
|
+
isDefined(b) ? getLength(a) < getLength(b) : c => isLengthSmaller(a, c)
|
|
118
|
+
|
|
119
|
+
export const isLengthSmallerOrEqual = (a, b) =>
|
|
120
|
+
isDefined(b) ? getLength(a) <= getLength(b) : c => isLengthSmallerOrEqual(a, c)
|
|
121
|
+
|
|
122
|
+
export const isIterable = e => isDefined(e) && !isNull(e) && isFunction(e.forEach)
|
|
123
|
+
|
|
124
|
+
export const isEmail = e => isString(e) && e.indexOf('@') > -1
|
|
125
|
+
|
|
126
|
+
export const isNull = e => e === null
|
|
127
|
+
|
|
128
|
+
export const isUndefinedOrNull = e => isNull(e) || !isDefined(e)
|
|
129
|
+
|
|
130
|
+
export const isBuffer = e => {
|
|
131
|
+
if (!e) {
|
|
132
|
+
return false
|
|
133
|
+
} else if (isEmpty(e)) {
|
|
134
|
+
return false
|
|
135
|
+
} else if (!isObject(e)) {
|
|
136
|
+
return false
|
|
137
|
+
} else if (!isFunction(e.copy)) {
|
|
138
|
+
return false
|
|
139
|
+
} else if (!isNumber(e[0])) {
|
|
140
|
+
return false
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return true
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export const isPromise = e => e && isFunction(e.then)
|
|
147
|
+
export const isThenable = isPromise
|
|
148
|
+
|
|
149
|
+
export const isArguments = e => Object.prototype.toString.call(e) === '[object Arguments]'
|
|
150
|
+
|
|
151
|
+
export const isUUID = e => {
|
|
152
|
+
if (!isDefined(e)) {
|
|
153
|
+
return false
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!isString(e)) {
|
|
157
|
+
return false
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const split = e.split('-')
|
|
161
|
+
if (!isLengthEqual(split, 5)) {
|
|
162
|
+
return false
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const lengths = [8, 4, 4, 4, 12]
|
|
166
|
+
if (lengths.some((l, i) => split[i].length !== l)) {
|
|
167
|
+
return false
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// hex strings end with 'f'
|
|
171
|
+
if (Object.values(e).some(s => s > 'f' || s < 0)) {
|
|
172
|
+
return false
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return true
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export const isType = (e, type) => typeof e === type || Object.prototype.toString(e) === type
|
|
179
|
+
|
|
180
|
+
export const isTypes = (e, ...types) => types.some(k => isType(e, k))
|
|
181
|
+
|
|
182
|
+
export const isEqual = (e, ...types) => isTypes(e, ...types)
|
|
183
|
+
|
|
184
|
+
export const isNot = (e, ...types) => !isTypes(e, ...types)
|
|
185
|
+
|
|
186
|
+
export const isComparable = a => isBoolean(a) || isString(a) || isNumber(a)
|
|
187
|
+
|
|
188
|
+
export const isSameType = (a, b) => typeof a === typeof b
|
|
189
|
+
|
|
190
|
+
const isElementCheck = (e, t) => (isFunction(t) ? t(e) : typeof e === t)
|
|
191
|
+
|
|
192
|
+
export const isEvery = (arr, t) =>
|
|
193
|
+
!isArray(arr) ? isElementCheck(arr, t) : arr.every(e => isElementCheck(e, t))
|
|
194
|
+
|
|
195
|
+
export const isSome = (arr, t) =>
|
|
196
|
+
!isArray(arr) ? isElementCheck(arr, t) : arr.some(e => isElementCheck(e, t))
|
|
197
|
+
|
|
198
|
+
export const isNone = (arr, t) => !isSome(arr, t)
|
|
199
|
+
|
|
200
|
+
export const isInstanceOf = (e, t) => (!t ? false : e instanceof t)
|
|
201
|
+
|
|
202
|
+
export const isError = e => isInstanceOf(e, Error)
|
|
203
|
+
export const isDate = e => isInstanceOf(e, Date)
|
|
204
|
+
export const isRegExp = e => isInstanceOf(e, RegExp)
|
|
205
|
+
export const isMap = a => isInstanceOf(a, Map)
|
|
206
|
+
export const isSet = a => isInstanceOf(a, Set)
|
|
207
|
+
export const isWeakMap = a => isInstanceOf(a, WeakMap)
|
|
208
|
+
export const isWeakSet = a => isInstanceOf(a, WeakSet)
|
|
209
|
+
|
|
210
|
+
export const isUpperCase = s => (isString(s) ? s === s.toUpperCase() : false)
|
|
211
|
+
export const isLowerCase = s => (isString(s) ? s === s.toLowerCase() : false)
|
|
212
|
+
|
|
213
|
+
export const isOwnProp = (o, k) =>
|
|
214
|
+
isDefined(o) && isFunction(o.hasOwnProperty) && o.hasOwnProperty(k)
|
|
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))
|
|
221
|
+
isCase.upper = isUpperCase
|
|
222
|
+
isCase.lower = isLowerCase
|
package/src/index.mjs
CHANGED
|
@@ -1,520 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import def from './lib.mjs'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import * as deep from './deep/index.mjs'
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
export const isDefined = e => typeof e !== 'undefined'
|
|
8
|
-
|
|
9
|
-
export const isUndefined = e => !isDefined(e)
|
|
10
|
-
|
|
11
|
-
export const isFunction = e => typeof e === 'function'
|
|
12
|
-
|
|
13
|
-
export const isAsyncFunction = e => Object.prototype.toString.call(e) === '[object AsyncFunction]'
|
|
14
|
-
|
|
15
|
-
export const isGeneratorFunction = e => Object.prototype.toString.call(e) === '[object GeneratorFunction]'
|
|
16
|
-
|
|
17
|
-
export const isNumber = e => typeof e !== 'object' && e === +e
|
|
18
|
-
|
|
19
|
-
export const isInteger = e => e === +e && e === (e | 0)
|
|
20
|
-
|
|
21
|
-
export const isFloat = e => e === +e
|
|
22
|
-
|
|
23
|
-
export const isObject = e => typeof e === 'object' && !isNull(e)
|
|
24
|
-
|
|
25
|
-
export const isObjectNative = e => Object.prototype.toString.call(e) === '[object Object]'
|
|
26
|
-
|
|
27
|
-
export const isMergeableObject = e => isObject(e) && !isDate(e) && !isRegExp(e)
|
|
28
|
-
|
|
29
|
-
export const isString = e => typeof e === 'string'
|
|
30
|
-
|
|
31
|
-
export const isRGBValue = e => ![e.r, e.g, e.b].some(n => !isNumber(n))
|
|
32
|
-
export const isRGBAValue = e => ![e.r, e.g, e.b, e.a].some(n => !isNumber(n))
|
|
33
|
-
|
|
34
|
-
export const isRGBAObject = e => isObject(e) && isRGBAValue(e)
|
|
35
|
-
|
|
36
|
-
export const isRGBObject = e => isObject(e) && isRGBValue(e)
|
|
37
|
-
|
|
38
|
-
export const hexRegex = /#\b([a-f0-9]{3}|[a-f0-9]{4}|[a-f0-9]{6}|[a-f0-9]{8})\b/i
|
|
39
|
-
export const isHexColor = e => hexRegex.test(e)
|
|
40
|
-
|
|
41
|
-
export const isHexColor3 = e => /#\b([a-f0-9]{3})\b/i.test(e)
|
|
42
|
-
|
|
43
|
-
export const isHexColor4 = e => /#\b([a-f0-9]{4})\b/i.test(e)
|
|
44
|
-
|
|
45
|
-
export const isHexColor6 = e => /#\b([a-f0-9]{6})\b/i.test(e)
|
|
46
|
-
|
|
47
|
-
export const isHexColor8 = e => /#\b([a-f0-9]{8})\b/i.test(e)
|
|
48
|
-
|
|
49
|
-
export const isHexAlphaColor = e => /#\b([a-f0-9]{4}|[a-f0-9]{8})\b/i.test(e)
|
|
50
|
-
|
|
51
|
-
export const isHexAlphaColor4 = e => /#\b([a-f0-9]{4})\b/i.test(e)
|
|
52
|
-
|
|
53
|
-
export const isHexAlphaColor8 = e => /#\b([a-f0-9]{8})\b/i.test(e)
|
|
54
|
-
|
|
55
|
-
export const isColor = e => isRGBAObject(e) || isRGBObject(e) || isHexColor(e) || isHexAlphaColor(e)
|
|
56
|
-
|
|
57
|
-
export const isTruthy = e => !!e
|
|
58
|
-
|
|
59
|
-
export const isFalsy = e => !e || isEmpty(e)
|
|
60
|
-
|
|
61
|
-
export const isEmpty = e => {
|
|
62
|
-
if (isError(e)) {
|
|
63
|
-
return false
|
|
64
|
-
} else if (isDate(e)) {
|
|
65
|
-
return false
|
|
66
|
-
} else if (isNull(e)) {
|
|
67
|
-
return true
|
|
68
|
-
} else if (isUndefined(e)) {
|
|
69
|
-
return true
|
|
70
|
-
} else if (isArray(e)) {
|
|
71
|
-
return isLengthSmaller(e, 1)
|
|
72
|
-
} else if (isRegExp(e)) {
|
|
73
|
-
return isLengthSmaller(e, 1)
|
|
74
|
-
} else if (isObject(e)) {
|
|
75
|
-
return isLengthSmaller(e, 1)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return e === 0 || e === '' || !e
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export const getLength = arg => {
|
|
82
|
-
if (isNumber(arg)) {
|
|
83
|
-
return arg
|
|
84
|
-
} else if (isNumber(arg.length)) {
|
|
85
|
-
// arrays, strings
|
|
86
|
-
return arg.length
|
|
87
|
-
} else if (isNumber(arg.size)) {
|
|
88
|
-
// Set, Map, WeakMap etc
|
|
89
|
-
return arg.size
|
|
90
|
-
} else if (isRegExp(arg)) {
|
|
91
|
-
const str = arg.toString()
|
|
92
|
-
if (str === '/(?:)/') {
|
|
93
|
-
return 0
|
|
94
|
-
} else {
|
|
95
|
-
return str.length > 2
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// objects
|
|
100
|
-
return Object.keys(arg).length
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export const compareCount = (len, e) => getLength(len) === getLength(e)
|
|
104
|
-
export const isLengthEqual = (a, b) => (isDefined(b) ? compareCount(a, b) : b => compareCount(a, b))
|
|
105
|
-
|
|
106
|
-
export const isLengthGreater = (a, b) =>
|
|
107
|
-
isDefined(b) ? getLength(a) > getLength(b) : c => isLengthGreater(a, c)
|
|
108
|
-
|
|
109
|
-
export const isLengthGreaterOrEqual = (a, b) =>
|
|
110
|
-
isDefined(b) ? getLength(a) >= getLength(b) : c => isLengthGreaterOrEqual(a, c)
|
|
111
|
-
|
|
112
|
-
export const isLengthSmaller = (a, b) =>
|
|
113
|
-
isDefined(b) ? getLength(a) < getLength(b) : c => isLengthSmaller(a, c)
|
|
114
|
-
|
|
115
|
-
export const isLengthSmallerOrEqual = (a, b) =>
|
|
116
|
-
isDefined(b) ? getLength(a) <= getLength(b) : c => isLengthSmallerOrEqual(a, c)
|
|
117
|
-
|
|
118
|
-
export const isIterable = e => isDefined(e) && !isNull(e) && isFunction(e.forEach)
|
|
119
|
-
|
|
120
|
-
export const isEmail = e => isString(e) && e.indexOf('@') > -1
|
|
121
|
-
|
|
122
|
-
export const isNull = e => e === null
|
|
123
|
-
|
|
124
|
-
export const isUndefinedOrNull = e => e === null || !isDefined(e)
|
|
125
|
-
|
|
126
|
-
export const isBuffer = e => {
|
|
127
|
-
if (!e) {
|
|
128
|
-
return false
|
|
129
|
-
} else if (isEmpty(e)) {
|
|
130
|
-
return false
|
|
131
|
-
} else if (!isObject(e)) {
|
|
132
|
-
return false
|
|
133
|
-
} else if (!isFunction(e.copy)) {
|
|
134
|
-
return false
|
|
135
|
-
} else if (!isNumber(e[0])) {
|
|
136
|
-
return false
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return true
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export const isPromise = e => e && isFunction(e.then)
|
|
143
|
-
|
|
144
|
-
export const isArguments = e => Object.prototype.toString.call(e) === '[object Arguments]'
|
|
145
|
-
|
|
146
|
-
export const isUUID = e => {
|
|
147
|
-
if (!isDefined(e)) {
|
|
148
|
-
return false
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (!isString(e)) {
|
|
152
|
-
return false
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const split = e.split('-')
|
|
156
|
-
if (!is.len.equal(split, 5)) {
|
|
157
|
-
return false
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const lengths = [8, 4, 4, 4, 12]
|
|
161
|
-
if (lengths.some((l, i) => split[i].length !== l)) {
|
|
162
|
-
return false
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// hex strings end with 'f'
|
|
166
|
-
if (Object.values(e).some(s => s > 'f' || s < 0)) {
|
|
167
|
-
return false
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return true
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export const isType = (e, type) => typeof e === type || Object.prototype.toString(e) === type
|
|
174
|
-
|
|
175
|
-
export const isTypes = (e, ...types) => types.some(k => isType(e, k))
|
|
176
|
-
|
|
177
|
-
export const isEqual = (e, ...types) => isTypes(e, ...types)
|
|
178
|
-
|
|
179
|
-
export const isNot = (e, ...types) => !isTypes(e, ...types)
|
|
180
|
-
|
|
181
|
-
export const isComparable = a => isBoolean(a) || isString(a) || isNumber(a)
|
|
182
|
-
|
|
183
|
-
const isElementCheck = (e, t) => (isFunction(t) ? t(e) : typeof e === t)
|
|
184
|
-
|
|
185
|
-
export const isEvery = (arr, t) =>
|
|
186
|
-
!isArray(arr) ? isElementCheck(arr, t) : arr.every(e => isElementCheck(e, t))
|
|
187
|
-
|
|
188
|
-
export const isSome = (arr, t) =>
|
|
189
|
-
!isArray(arr) ? isElementCheck(arr, t) : arr.some(e => isElementCheck(e, t))
|
|
190
|
-
|
|
191
|
-
export const isNone = (arr, t) => !isSome(arr, t)
|
|
192
|
-
|
|
193
|
-
export const isInstanceOf = (e, t) => e instanceof t
|
|
194
|
-
|
|
195
|
-
export const isError = e => isInstanceOf(e, Error)
|
|
196
|
-
export const isDate = e => isInstanceOf(e, Date)
|
|
197
|
-
export const isRegExp = e => isInstanceOf(e, RegExp)
|
|
198
|
-
export const isMap = a => isInstanceOf(a, Map)
|
|
199
|
-
export const isSet = a => isInstanceOf(a, Set)
|
|
200
|
-
export const isWeakMap = a => isInstanceOf(a, WeakMap)
|
|
201
|
-
export const isWeakSet = a => isInstanceOf(a, WeakSet)
|
|
202
|
-
|
|
203
|
-
export const isUpperCase = s => (isString(s) ? s === s.toUpperCase() : false)
|
|
204
|
-
export const isLowerCase = s => (isString(s) ? s === s.toLowerCase() : false)
|
|
205
|
-
|
|
206
|
-
export const isCase = (s, c = 'up') => (c === 'up' ? isUpperCase(s) : isLowerCase(s))
|
|
207
|
-
|
|
208
|
-
isCase.upper = isUpperCase
|
|
209
|
-
isCase.lower = isLowerCase
|
|
5
|
+
export * from './fns.mjs'
|
|
210
6
|
|
|
211
7
|
export const is = {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
len: getLength,
|
|
215
|
-
ln: getLength,
|
|
216
|
-
|
|
217
|
-
isError,
|
|
218
|
-
error: isError,
|
|
219
|
-
err: isError,
|
|
220
|
-
|
|
221
|
-
isIterable,
|
|
222
|
-
isIter: isIterable,
|
|
223
|
-
iterable: isIterable,
|
|
224
|
-
iter: isIterable,
|
|
225
|
-
|
|
226
|
-
isEmail,
|
|
227
|
-
isMail: isEmail,
|
|
228
|
-
email: isEmail,
|
|
229
|
-
mail: isEmail,
|
|
230
|
-
|
|
231
|
-
isNull,
|
|
232
|
-
isNil: isNull,
|
|
233
|
-
null: isNull,
|
|
234
|
-
nil: isNull,
|
|
235
|
-
|
|
236
|
-
isUndefinedOrNull,
|
|
237
|
-
undefinedOrNull: isUndefinedOrNull,
|
|
238
|
-
undefinedOrNil: isUndefinedOrNull,
|
|
239
|
-
undefOrNull: isUndefinedOrNull,
|
|
240
|
-
undefOrNil: isUndefinedOrNull,
|
|
241
|
-
|
|
242
|
-
isBuffer,
|
|
243
|
-
buffer: isBuffer,
|
|
244
|
-
buff: isBuffer,
|
|
245
|
-
|
|
246
|
-
isPromise,
|
|
247
|
-
promise: isPromise,
|
|
248
|
-
isThenable: isPromise,
|
|
249
|
-
isThen: isPromise,
|
|
250
|
-
thenable: isPromise,
|
|
251
|
-
then: isPromise,
|
|
252
|
-
|
|
253
|
-
// isArguments,
|
|
254
|
-
// isArgs: isArguments,
|
|
255
|
-
// arguments: isArguments,
|
|
256
|
-
// args: isArguments,
|
|
257
|
-
|
|
258
|
-
isUUID,
|
|
259
|
-
uuid: isUUID,
|
|
260
|
-
|
|
261
|
-
isType,
|
|
262
|
-
testType: isType,
|
|
263
|
-
type: isType,
|
|
264
|
-
|
|
265
|
-
isTypes,
|
|
266
|
-
test: isTypes,
|
|
267
|
-
types: isTypes,
|
|
268
|
-
|
|
269
|
-
isEmpty,
|
|
270
|
-
empty: isEmpty,
|
|
271
|
-
|
|
272
|
-
isEqual,
|
|
273
|
-
isEq: isEqual,
|
|
274
|
-
equal: isEqual,
|
|
275
|
-
eq: isEqual,
|
|
276
|
-
is: isEqual,
|
|
277
|
-
|
|
278
|
-
isNot,
|
|
279
|
-
not: isNot,
|
|
280
|
-
isNeq: isNot,
|
|
281
|
-
neq: isNot,
|
|
282
|
-
|
|
283
|
-
isArray,
|
|
284
|
-
isArr: isArray,
|
|
285
|
-
array: isArray,
|
|
286
|
-
arr: isArray,
|
|
287
|
-
|
|
288
|
-
isBoolean,
|
|
289
|
-
isBool: isBoolean,
|
|
290
|
-
boolean: isBoolean,
|
|
291
|
-
bool: isBoolean,
|
|
292
|
-
|
|
293
|
-
isDefined,
|
|
294
|
-
isDef: isDefined,
|
|
295
|
-
defined: isDefined,
|
|
296
|
-
def: isDefined,
|
|
297
|
-
|
|
298
|
-
isUndefined,
|
|
299
|
-
isUndef: isUndefined,
|
|
300
|
-
undefined: isUndefined,
|
|
301
|
-
undef: isUndefined,
|
|
302
|
-
|
|
303
|
-
isFunction,
|
|
304
|
-
isFunc: isFunction,
|
|
305
|
-
isFn: isFunction,
|
|
306
|
-
function: isFunction,
|
|
307
|
-
func: isFunction,
|
|
308
|
-
fn: isFunction,
|
|
309
|
-
|
|
310
|
-
isAsyncFunction,
|
|
311
|
-
isAsyncFunc: isAsyncFunction,
|
|
312
|
-
isAsyncFn: isAsyncFunction,
|
|
313
|
-
asyncFunction: isAsyncFunction,
|
|
314
|
-
asyncFunc: isAsyncFunction,
|
|
315
|
-
asyncFn: isAsyncFunction,
|
|
316
|
-
|
|
317
|
-
isGeneratorFunction,
|
|
318
|
-
isGeneratorFn: isGeneratorFunction,
|
|
319
|
-
isGeneratorFunc: isGeneratorFunction,
|
|
320
|
-
isGeneratorFn: isGeneratorFunction,
|
|
321
|
-
generator: isGeneratorFunction,
|
|
322
|
-
isGenerator: isGeneratorFunction,
|
|
323
|
-
generatorFn: isGeneratorFunction,
|
|
324
|
-
generatorFunc: isGeneratorFunction,
|
|
325
|
-
generatorFunction: isGeneratorFunction,
|
|
326
|
-
|
|
327
|
-
isNumber,
|
|
328
|
-
isNum: isNumber,
|
|
329
|
-
number: isNumber,
|
|
330
|
-
num: isNumber,
|
|
331
|
-
|
|
332
|
-
isInteger,
|
|
333
|
-
isInt: isInteger,
|
|
334
|
-
integer: isInteger,
|
|
335
|
-
int: isInteger,
|
|
336
|
-
|
|
337
|
-
isFloat,
|
|
338
|
-
float: isFloat,
|
|
339
|
-
|
|
340
|
-
isObject,
|
|
341
|
-
isObj: isObject,
|
|
342
|
-
object: isObject,
|
|
343
|
-
obj: isObject,
|
|
344
|
-
|
|
345
|
-
isObjectNative,
|
|
346
|
-
objectNative: isObjectNative,
|
|
347
|
-
|
|
348
|
-
isMergeableObject,
|
|
349
|
-
mergeableObject: isMergeableObject,
|
|
350
|
-
isMergeable: isMergeableObject,
|
|
351
|
-
mergeable: isMergeableObject,
|
|
352
|
-
|
|
353
|
-
isString,
|
|
354
|
-
isStr: isString,
|
|
355
|
-
string: isString,
|
|
356
|
-
str: isString,
|
|
357
|
-
|
|
358
|
-
isRGBAObject,
|
|
359
|
-
isRGBA: isRGBAObject,
|
|
360
|
-
rgbaObject: isRGBAObject,
|
|
361
|
-
rgba: isRGBAObject,
|
|
362
|
-
|
|
363
|
-
isRGBObject,
|
|
364
|
-
isRGB: isRGBObject,
|
|
365
|
-
rgbObject: isRGBObject,
|
|
366
|
-
rgb: isRGBObject,
|
|
367
|
-
|
|
368
|
-
isHexColor,
|
|
369
|
-
isHex: isHexColor,
|
|
370
|
-
hexColor: isHexColor,
|
|
371
|
-
hex: isHexColor,
|
|
372
|
-
|
|
373
|
-
isHexColor3,
|
|
374
|
-
isHex3: isHexColor3,
|
|
375
|
-
hexColor3: isHexColor3,
|
|
376
|
-
hex3: isHexColor3,
|
|
377
|
-
|
|
378
|
-
isHexColor4,
|
|
379
|
-
isHex4: isHexColor4,
|
|
380
|
-
hexColor4: isHexColor4,
|
|
381
|
-
hex4: isHexColor4,
|
|
382
|
-
|
|
383
|
-
isHexColor6,
|
|
384
|
-
isHex6: isHexColor6,
|
|
385
|
-
hexColor6: isHexColor6,
|
|
386
|
-
hex6: isHexColor6,
|
|
387
|
-
|
|
388
|
-
isHexColor8,
|
|
389
|
-
isHex8: isHexColor8,
|
|
390
|
-
hexColor8: isHexColor8,
|
|
391
|
-
hex8: isHexColor8,
|
|
392
|
-
|
|
393
|
-
isHexAlphaColor,
|
|
394
|
-
isHexa: isHexAlphaColor,
|
|
395
|
-
hexAlphaColor: isHexAlphaColor,
|
|
396
|
-
hexa: isHexAlphaColor,
|
|
397
|
-
|
|
398
|
-
isHexAlphaColor4,
|
|
399
|
-
isHexa4: isHexAlphaColor4,
|
|
400
|
-
hexAlphaColor4: isHexAlphaColor4,
|
|
401
|
-
hexa4: isHexAlphaColor4,
|
|
402
|
-
|
|
403
|
-
isHexAlphaColor8,
|
|
404
|
-
isHexa8: isHexAlphaColor8,
|
|
405
|
-
hexAlphaColor8: isHexAlphaColor8,
|
|
406
|
-
hexa8: isHexAlphaColor8,
|
|
407
|
-
|
|
408
|
-
isColor,
|
|
409
|
-
isCol: isColor,
|
|
410
|
-
color: isColor,
|
|
411
|
-
col: isColor,
|
|
412
|
-
|
|
413
|
-
isComparable,
|
|
414
|
-
Comparable: isComparable,
|
|
415
|
-
comparable: isComparable,
|
|
416
|
-
|
|
417
|
-
isDate,
|
|
418
|
-
isTime: isDate,
|
|
419
|
-
date: isDate,
|
|
420
|
-
time: isDate,
|
|
421
|
-
|
|
422
|
-
isRegExp,
|
|
423
|
-
isRegex: isRegExp,
|
|
424
|
-
regExp: isRegExp,
|
|
425
|
-
regexp: isRegExp,
|
|
426
|
-
regex: isRegExp,
|
|
427
|
-
|
|
428
|
-
isTruthy,
|
|
429
|
-
truthy: isTruthy,
|
|
430
|
-
|
|
431
|
-
isFalsy,
|
|
432
|
-
falsy: isFalsy,
|
|
433
|
-
|
|
434
|
-
isDeepEqual: deep.equal,
|
|
435
|
-
deepEqual: deep.equal,
|
|
436
|
-
deepEq: deep.equal,
|
|
437
|
-
|
|
438
|
-
isDeepDifferent: deep.different,
|
|
439
|
-
deepDifferent: deep.different,
|
|
440
|
-
deepDiff: deep.different,
|
|
441
|
-
|
|
442
|
-
deep: {
|
|
443
|
-
isDifferent: deep.different,
|
|
444
|
-
different: deep.different,
|
|
445
|
-
diff: deep.different,
|
|
446
|
-
|
|
447
|
-
isEqual: deep.equal,
|
|
448
|
-
equal: deep.equal,
|
|
449
|
-
eq: deep.equal,
|
|
450
|
-
},
|
|
451
|
-
|
|
452
|
-
isLengthGreater,
|
|
453
|
-
isLengthGreaterOrEqual,
|
|
454
|
-
isLengthSmaller,
|
|
455
|
-
isLengthSmallerOrEqual,
|
|
456
|
-
isLengthEqual,
|
|
457
|
-
|
|
458
|
-
isMap,
|
|
459
|
-
map: isMap,
|
|
460
|
-
|
|
461
|
-
isSet,
|
|
462
|
-
set: isSet,
|
|
463
|
-
|
|
464
|
-
isWeakMap,
|
|
465
|
-
weakMap: isWeakMap,
|
|
466
|
-
|
|
467
|
-
isWeakSet,
|
|
468
|
-
weakSet: isWeakSet,
|
|
469
|
-
|
|
470
|
-
every: isEvery,
|
|
471
|
-
all: isEvery,
|
|
472
|
-
some: isSome,
|
|
473
|
-
none: isNone,
|
|
474
|
-
|
|
475
|
-
instance: isInstanceOf,
|
|
476
|
-
instanceof: isInstanceOf,
|
|
477
|
-
instanceOf: isInstanceOf,
|
|
478
|
-
|
|
479
|
-
isCase,
|
|
480
|
-
case: isCase,
|
|
481
|
-
|
|
482
|
-
isUpperCase,
|
|
483
|
-
upperCase: isUpperCase,
|
|
484
|
-
isLowerCase,
|
|
485
|
-
lowerCase: isLowerCase,
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
// assign ln as properties of the getLength function
|
|
489
|
-
const ln = {
|
|
490
|
-
eq: isLengthEqual,
|
|
491
|
-
equal: isLengthEqual,
|
|
492
|
-
greater: isLengthGreater,
|
|
493
|
-
gt: isLengthGreater,
|
|
494
|
-
bigger: isLengthGreater,
|
|
495
|
-
biggerequal: isLengthGreaterOrEqual,
|
|
496
|
-
greater: isLengthGreater,
|
|
497
|
-
greaterequal: isLengthGreaterOrEqual,
|
|
498
|
-
gte: isLengthGreaterOrEqual,
|
|
499
|
-
gteq: isLengthGreaterOrEqual,
|
|
500
|
-
|
|
501
|
-
lower: isLengthSmaller,
|
|
502
|
-
smaller: isLengthSmaller,
|
|
503
|
-
lt: isLengthSmaller,
|
|
504
|
-
lowerequal: isLengthSmallerOrEqual,
|
|
505
|
-
smallerequal: isLengthSmallerOrEqual,
|
|
506
|
-
lte: isLengthSmallerOrEqual,
|
|
507
|
-
lteq: isLengthSmallerOrEqual,
|
|
8
|
+
...deep,
|
|
9
|
+
...def,
|
|
508
10
|
}
|
|
509
11
|
|
|
510
|
-
// count, length, len and ln are functions, returning the length.
|
|
511
|
-
// the code below assigns all keys in the ln object to each of those functions,
|
|
512
|
-
// allowing users of this library to call is.length.equal and other subfunctions.
|
|
513
|
-
|
|
514
|
-
const applyLenKey = (k, fn) => key => (is[key][k] = fn)
|
|
515
|
-
|
|
516
|
-
const applyLenKeys = ([k, fn]) => ['count', 'length', 'len', 'ln'].forEach(applyLenKey(k, fn))
|
|
517
|
-
|
|
518
|
-
Object.entries(ln).forEach(applyLenKeys)
|
|
519
|
-
|
|
520
12
|
export default is
|
package/src/lib.mjs
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import * as fns from './fns.mjs'
|
|
2
|
+
|
|
3
|
+
export const is = {
|
|
4
|
+
count: fns.getLength,
|
|
5
|
+
length: fns.getLength,
|
|
6
|
+
len: fns.getLength,
|
|
7
|
+
ln: fns.getLength,
|
|
8
|
+
|
|
9
|
+
isError: fns.isError,
|
|
10
|
+
error: fns.isError,
|
|
11
|
+
err: fns.isError,
|
|
12
|
+
|
|
13
|
+
isIterable: fns.isIterable,
|
|
14
|
+
isIter: fns.isIterable,
|
|
15
|
+
iterable: fns.isIterable,
|
|
16
|
+
iter: fns.isIterable,
|
|
17
|
+
|
|
18
|
+
isEmail: fns.isEmail,
|
|
19
|
+
isMail: fns.isEmail,
|
|
20
|
+
email: fns.isEmail,
|
|
21
|
+
mail: fns.isEmail,
|
|
22
|
+
|
|
23
|
+
isNull: fns.isNull,
|
|
24
|
+
isNil: fns.isNull,
|
|
25
|
+
null: fns.isNull,
|
|
26
|
+
nil: fns.isNull,
|
|
27
|
+
|
|
28
|
+
isUndefinedOrNull: fns.isUndefinedOrNull,
|
|
29
|
+
undefinedOrNull: fns.isUndefinedOrNull,
|
|
30
|
+
undefinedOrNil: fns.isUndefinedOrNull,
|
|
31
|
+
undefOrNull: fns.isUndefinedOrNull,
|
|
32
|
+
undefOrNil: fns.isUndefinedOrNull,
|
|
33
|
+
|
|
34
|
+
isBuffer: fns.isBuffer,
|
|
35
|
+
buffer: fns.isBuffer,
|
|
36
|
+
buff: fns.isBuffer,
|
|
37
|
+
|
|
38
|
+
isPromise: fns.isPromise,
|
|
39
|
+
promise: fns.isPromise,
|
|
40
|
+
isThenable: fns.isPromise,
|
|
41
|
+
isThen: fns.isPromise,
|
|
42
|
+
thenable: fns.isPromise,
|
|
43
|
+
then: fns.isPromise,
|
|
44
|
+
|
|
45
|
+
// isArguments: fns.isArguments,
|
|
46
|
+
// isArgs: fns.isArguments,
|
|
47
|
+
// arguments: fns.isArguments,
|
|
48
|
+
// args: fns.isArguments,
|
|
49
|
+
|
|
50
|
+
isUUID: fns.isUUID,
|
|
51
|
+
uuid: fns.isUUID,
|
|
52
|
+
|
|
53
|
+
isType: fns.isType,
|
|
54
|
+
testType: fns.isType,
|
|
55
|
+
type: fns.isType,
|
|
56
|
+
|
|
57
|
+
isTypes: fns.isTypes,
|
|
58
|
+
test: fns.isTypes,
|
|
59
|
+
types: fns.isTypes,
|
|
60
|
+
|
|
61
|
+
isEmpty: fns.isEmpty,
|
|
62
|
+
empty: fns.isEmpty,
|
|
63
|
+
|
|
64
|
+
isEqual: fns.isEqual,
|
|
65
|
+
isEq: fns.isEqual,
|
|
66
|
+
equal: fns.isEqual,
|
|
67
|
+
eq: fns.isEqual,
|
|
68
|
+
is: fns.isEqual,
|
|
69
|
+
|
|
70
|
+
isNot: fns.isNot,
|
|
71
|
+
not: fns.isNot,
|
|
72
|
+
isNeq: fns.isNot,
|
|
73
|
+
neq: fns.isNot,
|
|
74
|
+
|
|
75
|
+
isArray: fns.isArray,
|
|
76
|
+
isArr: fns.isArray,
|
|
77
|
+
array: fns.isArray,
|
|
78
|
+
arr: fns.isArray,
|
|
79
|
+
|
|
80
|
+
isBoolean: fns.isBoolean,
|
|
81
|
+
isBool: fns.isBoolean,
|
|
82
|
+
boolean: fns.isBoolean,
|
|
83
|
+
bool: fns.isBoolean,
|
|
84
|
+
|
|
85
|
+
isDefined: fns.isDefined,
|
|
86
|
+
isDef: fns.isDefined,
|
|
87
|
+
defined: fns.isDefined,
|
|
88
|
+
def: fns.isDefined,
|
|
89
|
+
|
|
90
|
+
isUndefined: fns.isUndefined,
|
|
91
|
+
isUndef: fns.isUndefined,
|
|
92
|
+
undefined: fns.isUndefined,
|
|
93
|
+
undef: fns.isUndefined,
|
|
94
|
+
|
|
95
|
+
isFunction: fns.isFunction,
|
|
96
|
+
isFunc: fns.isFunction,
|
|
97
|
+
isFn: fns.isFunction,
|
|
98
|
+
function: fns.isFunction,
|
|
99
|
+
func: fns.isFunction,
|
|
100
|
+
fn: fns.isFunction,
|
|
101
|
+
|
|
102
|
+
isAsyncFunction: fns.isAsyncFunction,
|
|
103
|
+
isAsyncFunc: fns.isAsyncFunction,
|
|
104
|
+
isAsyncFn: fns.isAsyncFunction,
|
|
105
|
+
asyncFunction: fns.isAsyncFunction,
|
|
106
|
+
asyncFunc: fns.isAsyncFunction,
|
|
107
|
+
asyncFn: fns.isAsyncFunction,
|
|
108
|
+
|
|
109
|
+
isGeneratorFunction: fns.isGeneratorFunction,
|
|
110
|
+
isGeneratorFn: fns.isGeneratorFunction,
|
|
111
|
+
isGeneratorFunc: fns.isGeneratorFunction,
|
|
112
|
+
isGeneratorFn: fns.isGeneratorFunction,
|
|
113
|
+
generator: fns.isGeneratorFunction,
|
|
114
|
+
isGenerator: fns.isGeneratorFunction,
|
|
115
|
+
generatorFn: fns.isGeneratorFunction,
|
|
116
|
+
generatorFunc: fns.isGeneratorFunction,
|
|
117
|
+
generatorFunction: fns.isGeneratorFunction,
|
|
118
|
+
|
|
119
|
+
isNumber: fns.isNumber,
|
|
120
|
+
isNum: fns.isNumber,
|
|
121
|
+
number: fns.isNumber,
|
|
122
|
+
num: fns.isNumber,
|
|
123
|
+
|
|
124
|
+
isInteger: fns.isInteger,
|
|
125
|
+
isInt: fns.isInteger,
|
|
126
|
+
integer: fns.isInteger,
|
|
127
|
+
int: fns.isInteger,
|
|
128
|
+
|
|
129
|
+
isFloat: fns.isFloat,
|
|
130
|
+
float: fns.isFloat,
|
|
131
|
+
|
|
132
|
+
isObject: fns.isObject,
|
|
133
|
+
isObj: fns.isObject,
|
|
134
|
+
object: fns.isObject,
|
|
135
|
+
obj: fns.isObject,
|
|
136
|
+
|
|
137
|
+
isObjectNative: fns.isObjectNative,
|
|
138
|
+
objectNative: fns.isObjectNative,
|
|
139
|
+
|
|
140
|
+
isMergeableObject: fns.isMergeableObject,
|
|
141
|
+
mergeableObject: fns.isMergeableObject,
|
|
142
|
+
isMergeable: fns.isMergeableObject,
|
|
143
|
+
mergeable: fns.isMergeableObject,
|
|
144
|
+
|
|
145
|
+
isString: fns.isString,
|
|
146
|
+
isStr: fns.isString,
|
|
147
|
+
string: fns.isString,
|
|
148
|
+
str: fns.isString,
|
|
149
|
+
|
|
150
|
+
isRGBAObject: fns.isRGBAObject,
|
|
151
|
+
isRGBA: fns.isRGBAObject,
|
|
152
|
+
rgbaObject: fns.isRGBAObject,
|
|
153
|
+
rgba: fns.isRGBAObject,
|
|
154
|
+
|
|
155
|
+
isRGBObject: fns.isRGBObject,
|
|
156
|
+
isRGB: fns.isRGBObject,
|
|
157
|
+
rgbObject: fns.isRGBObject,
|
|
158
|
+
rgb: fns.isRGBObject,
|
|
159
|
+
|
|
160
|
+
isHexColor: fns.isHexColor,
|
|
161
|
+
isHex: fns.isHexColor,
|
|
162
|
+
hexColor: fns.isHexColor,
|
|
163
|
+
hex: fns.isHexColor,
|
|
164
|
+
|
|
165
|
+
isHexColor3: fns.isHexColor3,
|
|
166
|
+
isHex3: fns.isHexColor3,
|
|
167
|
+
hexColor3: fns.isHexColor3,
|
|
168
|
+
hex3: fns.isHexColor3,
|
|
169
|
+
|
|
170
|
+
isHexColor4: fns.isHexColor4,
|
|
171
|
+
isHex4: fns.isHexColor4,
|
|
172
|
+
hexColor4: fns.isHexColor4,
|
|
173
|
+
hex4: fns.isHexColor4,
|
|
174
|
+
|
|
175
|
+
isHexColor6: fns.isHexColor6,
|
|
176
|
+
isHex6: fns.isHexColor6,
|
|
177
|
+
hexColor6: fns.isHexColor6,
|
|
178
|
+
hex6: fns.isHexColor6,
|
|
179
|
+
|
|
180
|
+
isHexColor8: fns.isHexColor8,
|
|
181
|
+
isHex8: fns.isHexColor8,
|
|
182
|
+
hexColor8: fns.isHexColor8,
|
|
183
|
+
hex8: fns.isHexColor8,
|
|
184
|
+
|
|
185
|
+
isHexAlphaColor: fns.isHexAlphaColor,
|
|
186
|
+
isHexa: fns.isHexAlphaColor,
|
|
187
|
+
hexAlphaColor: fns.isHexAlphaColor,
|
|
188
|
+
hexa: fns.isHexAlphaColor,
|
|
189
|
+
|
|
190
|
+
isHexAlphaColor4: fns.isHexAlphaColor4,
|
|
191
|
+
isHexa4: fns.isHexAlphaColor4,
|
|
192
|
+
hexAlphaColor4: fns.isHexAlphaColor4,
|
|
193
|
+
hexa4: fns.isHexAlphaColor4,
|
|
194
|
+
|
|
195
|
+
isHexAlphaColor8: fns.isHexAlphaColor8,
|
|
196
|
+
isHexa8: fns.isHexAlphaColor8,
|
|
197
|
+
hexAlphaColor8: fns.isHexAlphaColor8,
|
|
198
|
+
hexa8: fns.isHexAlphaColor8,
|
|
199
|
+
|
|
200
|
+
isColor: fns.isColor,
|
|
201
|
+
isCol: fns.isColor,
|
|
202
|
+
color: fns.isColor,
|
|
203
|
+
col: fns.isColor,
|
|
204
|
+
|
|
205
|
+
isComparable: fns.isComparable,
|
|
206
|
+
Comparable: fns.isComparable,
|
|
207
|
+
comparable: fns.isComparable,
|
|
208
|
+
|
|
209
|
+
isDate: fns.isDate,
|
|
210
|
+
isTime: fns.isDate,
|
|
211
|
+
date: fns.isDate,
|
|
212
|
+
time: fns.isDate,
|
|
213
|
+
|
|
214
|
+
isRegExp: fns.isRegExp,
|
|
215
|
+
isRegex: fns.isRegExp,
|
|
216
|
+
regExp: fns.isRegExp,
|
|
217
|
+
regexp: fns.isRegExp,
|
|
218
|
+
regex: fns.isRegExp,
|
|
219
|
+
|
|
220
|
+
isTruthy: fns.isTruthy,
|
|
221
|
+
truthy: fns.isTruthy,
|
|
222
|
+
|
|
223
|
+
isFalsy: fns.isFalsy,
|
|
224
|
+
falsy: fns.isFalsy,
|
|
225
|
+
|
|
226
|
+
isLengthGreater: fns.isLengthGreater,
|
|
227
|
+
isLengthGreaterOrEqual: fns.isLengthGreaterOrEqual,
|
|
228
|
+
isLengthSmaller: fns.isLengthSmaller,
|
|
229
|
+
isLengthSmallerOrEqual: fns.isLengthSmallerOrEqual,
|
|
230
|
+
isLengthEqual: fns.isLengthEqual,
|
|
231
|
+
|
|
232
|
+
isMap: fns.isMap,
|
|
233
|
+
map: fns.isMap,
|
|
234
|
+
|
|
235
|
+
isSet: fns.isSet,
|
|
236
|
+
set: fns.isSet,
|
|
237
|
+
|
|
238
|
+
isWeakMap: fns.isWeakMap,
|
|
239
|
+
weakMap: fns.isWeakMap,
|
|
240
|
+
|
|
241
|
+
isWeakSet: fns.isWeakSet,
|
|
242
|
+
weakSet: fns.isWeakSet,
|
|
243
|
+
|
|
244
|
+
every: fns.isEvery,
|
|
245
|
+
all: fns.isEvery,
|
|
246
|
+
some: fns.isSome,
|
|
247
|
+
none: fns.isNone,
|
|
248
|
+
|
|
249
|
+
instance: fns.isInstanceOf,
|
|
250
|
+
instanceof: fns.isInstanceOf,
|
|
251
|
+
instanceOf: fns.isInstanceOf,
|
|
252
|
+
|
|
253
|
+
isCase: fns.isCase,
|
|
254
|
+
case: fns.isCase,
|
|
255
|
+
|
|
256
|
+
isUpperCase: fns.isUpperCase,
|
|
257
|
+
upperCase: fns.isUpperCase,
|
|
258
|
+
isLowerCase: fns.isLowerCase,
|
|
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,
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// assign ln as properties of the getLength function
|
|
277
|
+
const ln = {
|
|
278
|
+
eq: fns.isLengthEqual,
|
|
279
|
+
equal: fns.isLengthEqual,
|
|
280
|
+
greater: fns.isLengthGreater,
|
|
281
|
+
gt: fns.isLengthGreater,
|
|
282
|
+
bigger: fns.isLengthGreater,
|
|
283
|
+
biggerequal: fns.isLengthGreaterOrEqual,
|
|
284
|
+
greater: fns.isLengthGreater,
|
|
285
|
+
greaterequal: fns.isLengthGreaterOrEqual,
|
|
286
|
+
gte: fns.isLengthGreaterOrEqual,
|
|
287
|
+
gteq: fns.isLengthGreaterOrEqual,
|
|
288
|
+
|
|
289
|
+
lower: fns.isLengthSmaller,
|
|
290
|
+
smaller: fns.isLengthSmaller,
|
|
291
|
+
lt: fns.isLengthSmaller,
|
|
292
|
+
lowerequal: fns.isLengthSmallerOrEqual,
|
|
293
|
+
smallerequal: fns.isLengthSmallerOrEqual,
|
|
294
|
+
lte: fns.isLengthSmallerOrEqual,
|
|
295
|
+
lteq: fns.isLengthSmallerOrEqual,
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// count, length, len and ln are functions, returning the length.
|
|
299
|
+
// the code below assigns all keys in the ln object to each of those functions,
|
|
300
|
+
// allowing users of this library to call is.length.equal and other subfunctions.
|
|
301
|
+
|
|
302
|
+
const applyLenKey = (k, fn) => key => (is[key][k] = fn)
|
|
303
|
+
|
|
304
|
+
const applyLenKeys = ([k, fn]) => ['count', 'length', 'len', 'ln'].forEach(applyLenKey(k, fn))
|
|
305
|
+
|
|
306
|
+
Object.entries(ln).forEach(applyLenKeys)
|
|
307
|
+
|
|
308
|
+
export default is
|