@mudbean/is 2.0.2 → 2.0.3
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/CHANGELOG.md +4 -0
- package/cjs/error.js +211 -1
- package/cjs/index.js +76 -1
- package/cjs/intl.js +152 -1
- package/cjs/isArray.js +340 -1
- package/cjs/isBoolean.js +71 -1
- package/cjs/isFunction.js +120 -1
- package/cjs/isNull.js +49 -1
- package/cjs/isNumber.js +148 -1
- package/cjs/isObject.js +200 -1
- package/cjs/isString.js +121 -1
- package/cjs/isSymbol.js +36 -1
- package/cjs/isType.js +16 -1
- package/cjs/typeOf.js +72 -1
- package/es/error.js +202 -1
- package/es/index.js +12 -1
- package/es/intl.js +145 -1
- package/es/isArray.js +323 -1
- package/es/isBoolean.js +67 -1
- package/es/isFunction.js +114 -1
- package/es/isNull.js +46 -1
- package/es/isNumber.js +141 -1
- package/es/isObject.js +193 -1
- package/es/isString.js +116 -1
- package/es/isSymbol.js +34 -1
- package/es/isType.js +14 -1
- package/es/typeOf.js +70 -1
- package/package.json +16 -23
- /package/es/{types/error.d.ts → error.d.ts} +0 -0
- /package/es/{types/index.d.ts → index.d.ts} +0 -0
- /package/es/{types/intl.d.ts → intl.d.ts} +0 -0
- /package/es/{types/isArray.d.ts → isArray.d.ts} +0 -0
- /package/es/{types/isBoolean.d.ts → isBoolean.d.ts} +0 -0
- /package/es/{types/isFunction.d.ts → isFunction.d.ts} +0 -0
- /package/es/{types/isNull.d.ts → isNull.d.ts} +0 -0
- /package/es/{types/isNumber.d.ts → isNumber.d.ts} +0 -0
- /package/es/{types/isObject.d.ts → isObject.d.ts} +0 -0
- /package/es/{types/isString.d.ts → isString.d.ts} +0 -0
- /package/es/{types/isSymbol.d.ts → isSymbol.d.ts} +0 -0
- /package/es/{types/isType.d.ts → isType.d.ts} +0 -0
- /package/es/{types/typeOf.d.ts → typeOf.d.ts} +0 -0
- /package/es/{types/types.d.ts → types.d.ts} +0 -0
package/cjs/isArray.js
CHANGED
|
@@ -1 +1,340 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var typeOf = require('./typeOf.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 检测 Javascript 数据类型工具之: array
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* # 检测 `input` 是否是 `Array` 类型
|
|
10
|
+
*
|
|
11
|
+
* @param input - 待检测的数据,任意类型
|
|
12
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `ReferenceError` ,且在 Typescript 中进行类型收缩
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { isArray } from '@mudbean/is';
|
|
17
|
+
*
|
|
18
|
+
* console.log(isArray([1,2,3])) // true
|
|
19
|
+
* console.log(isArray({})) // false
|
|
20
|
+
* console.log(isArray(new Set())) // false
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function isArray(input) {
|
|
24
|
+
return Array.isArray(input);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* # 检测 `input` 是否是空数组
|
|
28
|
+
*
|
|
29
|
+
* @param input - 待检测的数据,任意数组
|
|
30
|
+
* @returns 返回 `true` 则说明该数据 `input` 为长度为 0 的空数组 ,且在 Typescript 中进行类型收缩
|
|
31
|
+
* @example
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { isEmptyArray } from '@mudbean/is';
|
|
35
|
+
*
|
|
36
|
+
* console.log(isEmptyArray([])) // true
|
|
37
|
+
*
|
|
38
|
+
* console.log(isEmptyArray([1,2,3])) // false
|
|
39
|
+
* console.log(isEmptyArray({})) // TypeError
|
|
40
|
+
* console.log(isEmptyArray(new Set())) // false
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
function isEmptyArray(input) {
|
|
44
|
+
if (isArray(input)) {
|
|
45
|
+
return input.length === 0;
|
|
46
|
+
}
|
|
47
|
+
throw new TypeError('参数必须为数组');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* # 检测 `input` 是否是 `Set` 类型
|
|
51
|
+
*
|
|
52
|
+
* @param input - 待检测的数据,任意类型
|
|
53
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `ReferenceError` ,且在 Typescript 中进行类型收缩
|
|
54
|
+
* @example
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { isSet } from '@mudbean/is';
|
|
58
|
+
*
|
|
59
|
+
* console.log(isSet(new Set())) // true
|
|
60
|
+
* console.log(isSet({})) // false
|
|
61
|
+
* console.log(isSet([])) // false
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
function isSet(input) {
|
|
65
|
+
return typeOf.typeOf(input) === 'set';
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* # 检测 `input` 是否是 `WeakSet` 类型
|
|
69
|
+
*
|
|
70
|
+
* @param input - 待检测的数据,任意类型
|
|
71
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `WeakSet` ,且在 Typescript 中进行类型收缩
|
|
72
|
+
* @example
|
|
73
|
+
*
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { isWeakSet } from '@mudbean/is';
|
|
76
|
+
*
|
|
77
|
+
* console.log(isWeakSet(new WeakSet())) // true
|
|
78
|
+
*
|
|
79
|
+
* console.log(isWeakSet({})) // false
|
|
80
|
+
* console.log(isWeakSet([])) // false
|
|
81
|
+
* console.log(isWeakSet(1)) // false
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
function isWeakSet(input) {
|
|
85
|
+
return typeOf.typeOf(input) === 'weakset';
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* # 检测 `input` 是否是 `Bigint64Array` 类型
|
|
89
|
+
*
|
|
90
|
+
* @param input - 待检测的数据,任意类型
|
|
91
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `BigInt64Array` ,且在 Typescript 中进行类型收缩
|
|
92
|
+
* @example
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { isBigInt64Array } from '@mudbean/is';
|
|
96
|
+
*
|
|
97
|
+
* console.log(isBigInt64Array(new BigInt64Array())) // true
|
|
98
|
+
*
|
|
99
|
+
* console.log(isBigInt64Array({})) // false
|
|
100
|
+
* console.log(isBigInt64Array([])) // false
|
|
101
|
+
*
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
function isBigInt64Array(input) {
|
|
105
|
+
return typeOf.typeOf(input) === 'bigint64array';
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* # 检测 `input` 是否是 `BigUint64Array` 类型
|
|
109
|
+
*
|
|
110
|
+
* @param input - 待检测的数据,任意类型
|
|
111
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `BigUint64Array` ,且在 Typescript 中进行类型收缩
|
|
112
|
+
* @example
|
|
113
|
+
*
|
|
114
|
+
* ```ts
|
|
115
|
+
* import { isBigUint64Array } from '@mudbean/is';
|
|
116
|
+
*
|
|
117
|
+
* console.log(isBigUint64Array(new BigUint64Array())) // true
|
|
118
|
+
*
|
|
119
|
+
* console.log(isBigUint64Array({})) // false
|
|
120
|
+
* console.log(isBigUint64Array([])) // false
|
|
121
|
+
* console.log(isBigUint64Array(1)) // false
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
function isBigUint64Array(input) {
|
|
125
|
+
return typeOf.typeOf(input) === 'biguint64array';
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* # 检测 `input` 是否是 `ArrayBuffer` 类型
|
|
129
|
+
*
|
|
130
|
+
* @param input - 待检测的数据,任意类型
|
|
131
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `ArrayBuffer` ,且在 Typescript 中进行类型收缩
|
|
132
|
+
* @example
|
|
133
|
+
*
|
|
134
|
+
* ```ts
|
|
135
|
+
* import { isArrayBuffer } from '@mudbean/is';
|
|
136
|
+
*
|
|
137
|
+
* console.log(isArrayBuffer(new ArrayBuffer(8))) // true
|
|
138
|
+
*
|
|
139
|
+
* console.log(isArrayBuffer({})) // false
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
function isArrayBuffer(input) {
|
|
143
|
+
return typeOf.typeOf(input) === 'arraybuffer';
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* # 检测 `input` 是否是 `int8Array` 类型
|
|
147
|
+
*
|
|
148
|
+
* @param input - 待检测的数据,任意类型
|
|
149
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Int8Array` ,且在 Typescript 中进行类型收缩
|
|
150
|
+
* @example
|
|
151
|
+
*
|
|
152
|
+
* ```ts
|
|
153
|
+
* import { isInt8Array } from '@mudbean/is';
|
|
154
|
+
*
|
|
155
|
+
* console.log(isInt8Array(new Int8Array())) // true
|
|
156
|
+
*
|
|
157
|
+
* console.log(isInt8Array({})) // false
|
|
158
|
+
* console.log(isInt8Array([])) // false
|
|
159
|
+
* console.log(isInt8Array(1)) // false
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
function isInt8Array(input) {
|
|
163
|
+
return typeOf.typeOf(input) === 'int8array';
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* # 检测 `input` 是否是 `uint8Array` 类型
|
|
167
|
+
*
|
|
168
|
+
* @param input - 待检测的数据,任意类型
|
|
169
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Uint8Array` ,且在 Typescript 中进行类型收缩
|
|
170
|
+
* @example
|
|
171
|
+
*
|
|
172
|
+
* ```ts
|
|
173
|
+
* import { isUint8Array } from '@mudbean/is';
|
|
174
|
+
*
|
|
175
|
+
* console.log(isUint8Array(new Uint8Array())) // true
|
|
176
|
+
*
|
|
177
|
+
* console.log(isUint8Array({})) // false
|
|
178
|
+
* console.log(isUint8Array([])) // false
|
|
179
|
+
* console.log(isUint8Array(1)) // false
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
function isUint8Array(input) {
|
|
183
|
+
return typeOf.typeOf(input) === 'uint8array';
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* # 检测 `input` 是否是 `int16Array` 类型
|
|
187
|
+
*
|
|
188
|
+
* @param input - 待检测的数据,任意类型
|
|
189
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Int16Array` ,且在 Typescript 中进行类型收缩
|
|
190
|
+
* @example
|
|
191
|
+
*
|
|
192
|
+
* ```ts
|
|
193
|
+
* import { isInt16Array } from '@mudbean/is';
|
|
194
|
+
*
|
|
195
|
+
* console.log(isInt16Array(new Int16Array())) // true
|
|
196
|
+
*
|
|
197
|
+
* console.log(isInt16Array({})) // false
|
|
198
|
+
* console.log(isInt16Array([])) // false
|
|
199
|
+
* console.log(isInt16Array(1)) // false
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
function isInt16Array(input) {
|
|
203
|
+
return typeOf.typeOf(input) === 'int16array';
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* # 检测 `input` 是否是 `uint16Array` 类型
|
|
207
|
+
*
|
|
208
|
+
* @param input - 待检测的数据,任意类型
|
|
209
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Uint16Array` ,且在 Typescript 中进行类型收缩
|
|
210
|
+
* @example
|
|
211
|
+
*
|
|
212
|
+
* ```ts
|
|
213
|
+
*
|
|
214
|
+
* import { isUint16Array } from '@mudbean/is';
|
|
215
|
+
*
|
|
216
|
+
* console.log(isUint16Array(new Uint16Array())) // true
|
|
217
|
+
*
|
|
218
|
+
* console.log(isUint16Array({})) // false
|
|
219
|
+
* console.log(isUint16Array([])) // false
|
|
220
|
+
* console.log(isUint16Array(1)) // false
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
function isUint16Array(input) {
|
|
224
|
+
return typeOf.typeOf(input) === 'uint16array';
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* # 检测 `input` 是否是 `uint32Array` 类型
|
|
228
|
+
*
|
|
229
|
+
* @param input - 待检测的数据,任意类型
|
|
230
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Uint32Array` ,且在 Typescript 中进行类型收缩
|
|
231
|
+
* @example
|
|
232
|
+
*
|
|
233
|
+
* ```ts
|
|
234
|
+
* import { isUint32Array } from '@mudbean/is';
|
|
235
|
+
*
|
|
236
|
+
* console.log(isUint32Array(new Uint32Array())) // true
|
|
237
|
+
*
|
|
238
|
+
* console.log(isUint32Array({})) // false
|
|
239
|
+
* console.log(isUint32Array([])) // false
|
|
240
|
+
* console.log(isUint32Array(1)) // false
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
function isUint32Array(input) {
|
|
244
|
+
return typeOf.typeOf(input) === 'uint32array';
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* # 检测 `input` 是否是 `float32Array` 类型
|
|
248
|
+
*
|
|
249
|
+
* @param input - 待检测的数据,任意类型
|
|
250
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Float32Array` ,且在 Typescript 中进行类型收缩
|
|
251
|
+
* @example
|
|
252
|
+
*
|
|
253
|
+
* ```ts
|
|
254
|
+
* import { isFloat32Array } from '@mudbean/is';
|
|
255
|
+
*
|
|
256
|
+
* console.log(isFloat32Array(new Float32Array())) // true
|
|
257
|
+
*
|
|
258
|
+
* console.log(isFloat32Array({})) // false
|
|
259
|
+
* console.log(isFloat32Array([])) // false
|
|
260
|
+
* console.log(isFloat32Array(1)) // false
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
function isFloat32Array(input) {
|
|
264
|
+
return typeOf.typeOf(input) === 'float32array';
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* # 检测 `input` 是否是 `float64Array` 类型
|
|
268
|
+
*
|
|
269
|
+
* @param input - 待检测的数据,任意类型
|
|
270
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Float64Array` ,且在 Typescript 中进行类型收缩
|
|
271
|
+
* @example
|
|
272
|
+
*
|
|
273
|
+
* ```ts
|
|
274
|
+
* import { isFloat64Array } from '@mudbean/is';
|
|
275
|
+
*
|
|
276
|
+
* console.log(isFloat64Array(new Float64Array())) // true
|
|
277
|
+
*
|
|
278
|
+
* console.log(isFloat64Array({})) // false
|
|
279
|
+
* console.log(isFloat64Array([])) // false
|
|
280
|
+
* console.log(isFloat64Array(1)) // false
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
function isFloat64Array(input) {
|
|
284
|
+
return typeOf.typeOf(input) === 'float64array';
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* # 检测 `input` 是否是 `sharedArrayBuffer` 类型
|
|
288
|
+
*
|
|
289
|
+
* @param input - 待检测的数据,任意类型
|
|
290
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `SharedArrayBuffer` ,且在 Typescript 中进行类型收缩
|
|
291
|
+
* @example
|
|
292
|
+
*
|
|
293
|
+
* ```ts
|
|
294
|
+
* import { isSharedArrayBuffer } from '@mudbean/is';
|
|
295
|
+
*
|
|
296
|
+
* console.log(isSharedArrayBuffer(new SharedArrayBuffer(8))) // true
|
|
297
|
+
*
|
|
298
|
+
* console.log(isSharedArrayBuffer({})) // false
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
function isSharedArrayBuffer(input) {
|
|
302
|
+
return typeOf.typeOf(input) === 'sharedarraybuffer';
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* # 检测 `input` 是否是 `uint8ClampedArray` 类型
|
|
306
|
+
*
|
|
307
|
+
* @param input - 待检测的数据,任意类型
|
|
308
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Uint8ClampedArray` ,且在 Typescript 中进行类型收缩
|
|
309
|
+
* @example
|
|
310
|
+
*
|
|
311
|
+
* ```ts
|
|
312
|
+
* import { isUint8ClampedArray } from '@mudbean/is';
|
|
313
|
+
*
|
|
314
|
+
* console.log(isUint8ClampedArray(new Uint8ClampedArray())) // true
|
|
315
|
+
*
|
|
316
|
+
* console.log(isUint8ClampedArray({})) // false
|
|
317
|
+
* console.log(isUint8ClampedArray([])) // false
|
|
318
|
+
* console.log(isUint8ClampedArray(1)) // false
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
function isUint8ClampedArray(input) {
|
|
322
|
+
return typeOf.typeOf(input) === 'uint8clampedarray';
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
exports.isArray = isArray;
|
|
326
|
+
exports.isArrayBuffer = isArrayBuffer;
|
|
327
|
+
exports.isBigInt64Array = isBigInt64Array;
|
|
328
|
+
exports.isBigUint64Array = isBigUint64Array;
|
|
329
|
+
exports.isEmptyArray = isEmptyArray;
|
|
330
|
+
exports.isFloat32Array = isFloat32Array;
|
|
331
|
+
exports.isFloat64Array = isFloat64Array;
|
|
332
|
+
exports.isInt16Array = isInt16Array;
|
|
333
|
+
exports.isInt8Array = isInt8Array;
|
|
334
|
+
exports.isSet = isSet;
|
|
335
|
+
exports.isSharedArrayBuffer = isSharedArrayBuffer;
|
|
336
|
+
exports.isUint16Array = isUint16Array;
|
|
337
|
+
exports.isUint32Array = isUint32Array;
|
|
338
|
+
exports.isUint8Array = isUint8Array;
|
|
339
|
+
exports.isUint8ClampedArray = isUint8ClampedArray;
|
|
340
|
+
exports.isWeakSet = isWeakSet;
|
package/cjs/isBoolean.js
CHANGED
|
@@ -1 +1,71 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var typeOf = require('./typeOf.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 检测 Javascript 数据类型工具之: boolean
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* # 当前数据类型是否为 boolean
|
|
10
|
+
*
|
|
11
|
+
* @param input - 待检测的数据,任意类型
|
|
12
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `boolean` ,且在 Typescript 中进行类型收缩
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { isBoolean } from '@mudbean/is';
|
|
17
|
+
*
|
|
18
|
+
* console.log(isBoolean(true)); // true
|
|
19
|
+
* console.log(isBoolean(false)); // true
|
|
20
|
+
*
|
|
21
|
+
* console.log(isBoolean(1)); // false
|
|
22
|
+
* console.log(isBoolean('true')); // false
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function isBoolean(input) {
|
|
26
|
+
return typeOf.typeOf(input) === 'boolean';
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* # 当前数据类型是否为真值 true
|
|
30
|
+
*
|
|
31
|
+
* @param input - 待检测的数据,任意类型
|
|
32
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `true` ,且在 Typescript 中进行类型收缩
|
|
33
|
+
* @example
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { isTrue } from '@mudbean/is';
|
|
37
|
+
*
|
|
38
|
+
* console.log(isTrue(true)); // true
|
|
39
|
+
*
|
|
40
|
+
* console.log(isTrue(false)); // false
|
|
41
|
+
* console.log(isTrue(1)); // false
|
|
42
|
+
* console.log(isTrue('true')); // false
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function isTrue(input) {
|
|
46
|
+
return input === true;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* # 当前数据类型是否为真值 false
|
|
50
|
+
*
|
|
51
|
+
* @param input - 待检测的数据,任意类型
|
|
52
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `false` ,且在 Typescript 中进行类型收缩
|
|
53
|
+
* @example
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { isFalse } from '@mudbean/is';
|
|
57
|
+
*
|
|
58
|
+
* console.log(isFalse(false)); // true
|
|
59
|
+
*
|
|
60
|
+
* console.log(isFalse(true)); // false
|
|
61
|
+
* console.log(isFalse(1)); // false
|
|
62
|
+
* console.log(isFalse('true')); // false
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
function isFalse(input) {
|
|
66
|
+
return input === false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
exports.isBoolean = isBoolean;
|
|
70
|
+
exports.isFalse = isFalse;
|
|
71
|
+
exports.isTrue = isTrue;
|
package/cjs/isFunction.js
CHANGED
|
@@ -1 +1,120 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var typeOf = require('./typeOf.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 检测 Javascript 数据类型工具之: function
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* # 检测 `input` 是否是 `function` 类型
|
|
10
|
+
*
|
|
11
|
+
* 函数分类:
|
|
12
|
+
* - 普通函数
|
|
13
|
+
* - 使用 `async` 标注的异步函数
|
|
14
|
+
* - 使用 `*` 标注的生成器函数
|
|
15
|
+
*
|
|
16
|
+
* @param input - 待检测的数据,任意类型
|
|
17
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `function` ,且在 Typescript 中进行类型收缩
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { isFunction } from '@mudbean/is';
|
|
22
|
+
*
|
|
23
|
+
* console.log(isFunction(() => {})); // true
|
|
24
|
+
*
|
|
25
|
+
* console.log(isFunction(async () => {})); // false
|
|
26
|
+
* console.log(isFunction(function* () {})); // false
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function isFunction(input) {
|
|
30
|
+
return 'function' === typeOf.typeOf(input);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* # 检测 `input` 是否是 `Promise` 类型
|
|
34
|
+
*
|
|
35
|
+
* @param input - 待检测的数据,任意类型
|
|
36
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Promise` ,且在 Typescript 中进行类型收缩
|
|
37
|
+
* @example
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { isPromise } from '@mudbean/is';
|
|
41
|
+
*
|
|
42
|
+
* console.log(isPromise(new Promise(() => {}))); // true
|
|
43
|
+
* console.log(isPromise(() => {})); // false
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
function isPromise(input) {
|
|
47
|
+
return typeOf.typeOf(input) === 'promise';
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* # 检测 `input` 是否是 `AsyncFunction` 类型
|
|
51
|
+
*
|
|
52
|
+
* @param input - 待检测的数据,任意类型
|
|
53
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `async function` ,且在 Typescript 中进行类型收缩
|
|
54
|
+
* @example
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { isAsyncFunction } from '@mudbean/is';
|
|
58
|
+
*
|
|
59
|
+
* console.log(isAsyncFunction(async () => {})); // true
|
|
60
|
+
* console.log(isAsyncFunction(() => {})); // false
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
function isAsyncFunction(input) {
|
|
64
|
+
return typeOf.typeOf(input) === 'asyncfunction';
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* # 检测 `input` 是否是 `GeneratorFunction` 类型
|
|
68
|
+
*
|
|
69
|
+
* @param input - 待检测的数据,任意类型
|
|
70
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `generator function` ,且在 Typescript 中进行类型收缩
|
|
71
|
+
* @example
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { isGeneratorFunction } from '@mudbean/is';
|
|
75
|
+
*
|
|
76
|
+
* console.log(isGeneratorFunction(function* () {})); // true
|
|
77
|
+
* console.log(isGeneratorFunction(() => {})); // false
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
function isGeneratorFunction(input) {
|
|
82
|
+
return typeOf.typeOf(input) === 'generatorfunction';
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* # 检测 `input` 是否是 `Generator` 类型
|
|
86
|
+
*
|
|
87
|
+
* @param input - 待检测的数据,任意类型
|
|
88
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Generator` ,且在 Typescript 中进行类型收缩
|
|
89
|
+
* @example
|
|
90
|
+
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { isGenerator } from '@mudbean/is';
|
|
93
|
+
*
|
|
94
|
+
* const log = (str) => console.log(str);
|
|
95
|
+
* const foo = function* () {
|
|
96
|
+
* yield "a";
|
|
97
|
+
* yield "b";
|
|
98
|
+
* yield "c";
|
|
99
|
+
* }
|
|
100
|
+
*
|
|
101
|
+
* const gen = foo();
|
|
102
|
+
*
|
|
103
|
+
* log(gen.next().value); // a
|
|
104
|
+
* log(gen.next().value); // b
|
|
105
|
+
* log(gen.next().value); // c
|
|
106
|
+
*
|
|
107
|
+
* console.log(isGenerator(foo)); // false
|
|
108
|
+
* console.log(isGenerator(gen)); // true
|
|
109
|
+
*
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
function isGenerator(input) {
|
|
113
|
+
return typeOf.typeOf(input) === 'generator';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
exports.isAsyncFunction = isAsyncFunction;
|
|
117
|
+
exports.isFunction = isFunction;
|
|
118
|
+
exports.isGenerator = isGenerator;
|
|
119
|
+
exports.isGeneratorFunction = isGeneratorFunction;
|
|
120
|
+
exports.isPromise = isPromise;
|
package/cjs/isNull.js
CHANGED
|
@@ -1 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 检测 Javascript 数据类型工具之: null
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* 检测 `input` 是否是 `null` 类型
|
|
9
|
+
*
|
|
10
|
+
* @param input - 待检测的数据,任意类型
|
|
11
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `null` ,且在 Typescript 中进行类型收缩
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { isNull } from '@mudbean/is';
|
|
16
|
+
*
|
|
17
|
+
* console.log(isNull(null)); // true
|
|
18
|
+
*
|
|
19
|
+
* console.log(isNull(undefined)); // false
|
|
20
|
+
* console.log(isNull(1)); // false
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function isNull(input) {
|
|
24
|
+
return input === null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* 检测 `input` 是否是 `undefined` 类型
|
|
29
|
+
*
|
|
30
|
+
* @param input - 待检测的数据,任意类型
|
|
31
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `undefined` ,且在 Typescript 中进行类型收缩
|
|
32
|
+
* @example
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { isUndefined } from '@mudbean/is';
|
|
36
|
+
*
|
|
37
|
+
* console.log(isUndefined(undefined)); // true
|
|
38
|
+
*
|
|
39
|
+
* console.log(isUndefined(null)); // false
|
|
40
|
+
* console.log(isUndefined(1)); // false
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
function isUndefined(input) {
|
|
45
|
+
return input === undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.isNull = isNull;
|
|
49
|
+
exports.isUndefined = isUndefined;
|