@magic/types 0.1.23 → 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 +11 -1
- package/package.json +19 -12
- package/src/deep/different.js +33 -0
- package/src/deep/equal.js +146 -0
- package/src/deep/{index.mjs → index.js} +2 -2
- package/src/fns.js +630 -0
- package/src/index.js +8 -0
- package/src/{lib.mjs → lib.js} +18 -24
- package/types/deep/different.d.ts +14 -0
- package/types/deep/equal.d.ts +14 -0
- package/types/deep/index.d.ts +100 -0
- package/types/fns.d.ts +178 -0
- package/types/index.d.ts +508 -0
- package/types/lib.d.ts +507 -0
- package/src/deep/different.mjs +0 -18
- package/src/deep/equal.mjs +0 -108
- package/src/fns.mjs +0 -205
- package/src/index.mjs +0 -12
package/src/fns.mjs
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
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 (isArray(arg) || isString(arg) || isBuffer(arg)) {
|
|
83
|
-
return arg.length
|
|
84
|
-
} else if (isInteger(arg)) {
|
|
85
|
-
return arg
|
|
86
|
-
} else if (isMap(arg) || isWeakMap(arg) || isSet(arg) || isWeakSet(arg)) {
|
|
87
|
-
// Set, Map, WeakMap etc
|
|
88
|
-
return arg.size
|
|
89
|
-
} else if (isRegExp(arg)) {
|
|
90
|
-
const str = arg.toString()
|
|
91
|
-
if (str === '/(?:)/') {
|
|
92
|
-
return 0
|
|
93
|
-
} else {
|
|
94
|
-
return str.length > 2
|
|
95
|
-
}
|
|
96
|
-
} else if (isObjectNative(arg)) {
|
|
97
|
-
return Object.keys(arg).length
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// unknown things
|
|
101
|
-
return -1
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export const compareCount = (len, e) => getLength(len) === getLength(e)
|
|
105
|
-
export const isLengthEqual = (a, b) => (isDefined(b) ? compareCount(a, b) : b => compareCount(a, b))
|
|
106
|
-
|
|
107
|
-
export const isLengthGreater = (a, b) =>
|
|
108
|
-
isDefined(b) ? getLength(a) > getLength(b) : c => isLengthGreater(a, c)
|
|
109
|
-
|
|
110
|
-
export const isLengthGreaterOrEqual = (a, b) =>
|
|
111
|
-
isDefined(b) ? getLength(a) >= getLength(b) : c => isLengthGreaterOrEqual(a, c)
|
|
112
|
-
|
|
113
|
-
export const isLengthSmaller = (a, b) =>
|
|
114
|
-
isDefined(b) ? getLength(a) < getLength(b) : c => isLengthSmaller(a, c)
|
|
115
|
-
|
|
116
|
-
export const isLengthSmallerOrEqual = (a, b) =>
|
|
117
|
-
isDefined(b) ? getLength(a) <= getLength(b) : c => isLengthSmallerOrEqual(a, c)
|
|
118
|
-
|
|
119
|
-
export const isIterable = e => isDefined(e) && !isNull(e) && isFunction(e.forEach)
|
|
120
|
-
|
|
121
|
-
export const isEmail = e => isString(e) && e.indexOf('@') > -1
|
|
122
|
-
|
|
123
|
-
export const isNull = e => e === null
|
|
124
|
-
|
|
125
|
-
export const isUndefinedOrNull = e => isNull(e) || !isDefined(e)
|
|
126
|
-
|
|
127
|
-
export const isBuffer = e => Buffer.isBuffer(e)
|
|
128
|
-
|
|
129
|
-
export const isPromise = e => e && isFunction(e.then)
|
|
130
|
-
export const isThenable = isPromise
|
|
131
|
-
|
|
132
|
-
export const isArguments = e => Object.prototype.toString.call(e) === '[object Arguments]'
|
|
133
|
-
|
|
134
|
-
export const isUUID = e => {
|
|
135
|
-
if (!isDefined(e)) {
|
|
136
|
-
return false
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (!isString(e)) {
|
|
140
|
-
return false
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const split = e.split('-')
|
|
144
|
-
if (!isLengthEqual(split, 5)) {
|
|
145
|
-
return false
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const lengths = [8, 4, 4, 4, 12]
|
|
149
|
-
if (lengths.some((l, i) => split[i].length !== l)) {
|
|
150
|
-
return false
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// hex strings end with 'f'
|
|
154
|
-
if (Object.values(e).some(s => s > 'f' || s < 0)) {
|
|
155
|
-
return false
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return true
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export const isType = (e, type) => typeof e === type || Object.prototype.toString(e) === type
|
|
162
|
-
|
|
163
|
-
export const isTypes = (e, ...types) => types.some(k => isType(e, k))
|
|
164
|
-
|
|
165
|
-
export const isEqual = (e, ...types) => isTypes(e, ...types)
|
|
166
|
-
|
|
167
|
-
export const isNot = (e, ...types) => !isTypes(e, ...types)
|
|
168
|
-
|
|
169
|
-
export const isComparable = a => isBoolean(a) || isString(a) || isNumber(a)
|
|
170
|
-
|
|
171
|
-
export const isSameType = (a, b) => typeof a === typeof b
|
|
172
|
-
|
|
173
|
-
const isElementCheck = (e, t) => (isFunction(t) ? t(e) : typeof e === t)
|
|
174
|
-
|
|
175
|
-
export const isEvery = (arr, t) =>
|
|
176
|
-
!isArray(arr) ? isElementCheck(arr, t) : arr.every(e => isElementCheck(e, t))
|
|
177
|
-
|
|
178
|
-
export const isSome = (arr, t) =>
|
|
179
|
-
!isArray(arr) ? isElementCheck(arr, t) : arr.some(e => isElementCheck(e, t))
|
|
180
|
-
|
|
181
|
-
export const isNone = (arr, t) => !isSome(arr, t)
|
|
182
|
-
|
|
183
|
-
export const isInstanceOf = (e, t) => (!t ? false : e instanceof t)
|
|
184
|
-
|
|
185
|
-
export const isError = e => isInstanceOf(e, Error)
|
|
186
|
-
export const isDate = e => isInstanceOf(e, Date)
|
|
187
|
-
export const isRegExp = e => isInstanceOf(e, RegExp)
|
|
188
|
-
export const isMap = a => isInstanceOf(a, Map)
|
|
189
|
-
export const isSet = a => isInstanceOf(a, Set)
|
|
190
|
-
export const isWeakMap = a => isInstanceOf(a, WeakMap)
|
|
191
|
-
export const isWeakSet = a => isInstanceOf(a, WeakSet)
|
|
192
|
-
|
|
193
|
-
export const isUpperCase = s => (isString(s) ? s === s.toUpperCase() : false)
|
|
194
|
-
export const isLowerCase = s => (isString(s) ? s === s.toLowerCase() : false)
|
|
195
|
-
|
|
196
|
-
export const isOwnProp = (o, k) =>
|
|
197
|
-
isDefined(o) && isFunction(o.hasOwnProperty) && o.hasOwnProperty(k)
|
|
198
|
-
|
|
199
|
-
export const isOwnProperty = isOwnProp
|
|
200
|
-
|
|
201
|
-
export const isModule = s => Object.prototype.toString.call(s) === '[object Module]'
|
|
202
|
-
|
|
203
|
-
export const isCase = (s, c = 'up') => (c === 'up' ? isUpperCase(s) : isLowerCase(s))
|
|
204
|
-
isCase.upper = isUpperCase
|
|
205
|
-
isCase.lower = isLowerCase
|