IsPromiseLike
Usage
import {
isPromise,
isPromiseLike
} from 'is-promise-like'
isPromise
identifies instances of the global Promise
class.
isPromiseLike
identifies instances of the global Promise
class or other objects which are like them.
Examples: isPromise
Returns true
:
const p = new Promise(() => {})
isPromise(p)
const p = Promise.resolve({})
isPromise(p)
const p = Promise.all([])
isPromise(p)
Anything else should return false
.
Examples: isPromiseLike
All of the preceding examples returning true
. In addition:
class S {
static then () {}
}
isPromiseLike(S)
class S {
then () {}
}
const s = new S()
isPromiseLike(s)
const o = {}
o.then = () => {}
isPromiseLike(o)
const a = []
a.then = () => {}
isPromiseLike(a)
And similar constructions for other types. Anything else should return false
.