-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisPromise.js
More file actions
45 lines (43 loc) · 1.25 KB
/
isPromise.js
File metadata and controls
45 lines (43 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import _type from './utils/_type'
import isObject from './isObject'
import TYPES from './enum/types'
/**
* 检测数据是否为 Promise 对象
* ========================================================================
* @method isPromise
* @since 1.3.0
* @category Object
* @param {*} val - 测试数据
* @returns {Boolean} 'val' 是 Promise 对象,返回 true,否则返回 false
* @example
*
* const resolve = Promise.resolve
* const reject = Promise.reject
* const request = new Promise((resolve, reject) => {})
* let val
*
* // 非对象参数
* isPrototype(null) // => false
* isPrototype(val) // => false
* isPrototype('') // => false
* isPrototype(12) // => false
* isPrototype(false) // => false
* isPrototype(BigInt(12)) // => false
* isPrototype(Symbol('prop')) // => false
*
*
* // 对象参数
* isPrototype([]]) // => false
* isPrototype({}) // => false
* isPrototype(class {}) // => false
* isPrototype(() => {}) // => false
*
* isPrototype(request) // => true
* isPrototype(Promise.all([resolve, resolve]) // => true
* isPrototype(Promise.any([resolve, reject]) // => true
* isPrototype(resolve) // => true
*/
const isPromise = (val) => {
return isObject(val) && _type(val) === TYPES.PROMISE
}
export default isPromise